Ejemplo n.º 1
0
def create_patch_bundle(ui_, repo, freenet_heads, out_file):
    """ Creates an hg bundle file containing all the changesets
        later than freenet_heads. """

    freenet_heads = list(freenet_heads)
    freenet_heads.sort()
    # Make sure you have them all locally
    for head in freenet_heads:
        if not has_version(repo, head):
            raise util.Abort("The local repository isn't up to date. " +
                             "Run hg fn-pull.")

    heads = [hexlify(head) for head in repo.heads()]
    heads.sort()

    if freenet_heads == heads:
        raise util.Abort("All local changesets already in the repository " +
                         "in Freenet.")

    # Create a bundle using the freenet_heads as bases.
    ui_.pushbuffer()
    try:
        #print 'PARENTS:', freenet_heads
        #print 'HEADS:', heads
        commands.bundle(ui_,
                        repo,
                        out_file,
                        None,
                        base=list(freenet_heads),
                        rev=heads)
    finally:
        ui_.popbuffer()
Ejemplo n.º 2
0
def _getbundle(repo, dest, **opts):
    """return a bundle containing changesets missing in "dest"

    The `opts` keyword-arguments are the same as the one accepted by the
    `bundle` command.

    The bundle is a returned as a single in-memory binary blob.
    """
    ui = repo.ui
    tmpdir = pycompat.mkdtemp(prefix=b'hg-email-bundle-')
    tmpfn = os.path.join(tmpdir, b'bundle')
    btype = ui.config(b'patchbomb', b'bundletype')
    if btype:
        opts['type'] = btype
    try:
        dests = []
        if dest:
            dests = [dest]
        commands.bundle(ui, repo, tmpfn, *dests, **opts)
        return util.readfile(tmpfn)
    finally:
        try:
            os.unlink(tmpfn)
        except OSError:
            pass
        os.rmdir(tmpdir)
Ejemplo n.º 3
0
def create_patch_bundle(ui_, repo, freenet_heads, out_file):
    """ Creates an hg bundle file containing all the changesets
        later than freenet_heads. """

    freenet_heads = list(freenet_heads)
    freenet_heads.sort()
    # Make sure you have them all locally
    for head in freenet_heads:
        if not has_version(repo, head):
            raise util.Abort("The local repository isn't up to date. " +
                             "Run hg fn-pull.")

    heads = [hexlify(head) for head in repo.heads()]
    heads.sort()

    if freenet_heads == heads:
        raise util.Abort("All local changesets already in the repository " +
                         "in Freenet.")

    # Create a bundle using the freenet_heads as bases.
    ui_.pushbuffer()
    try:
        #print 'PARENTS:', freenet_heads
        #print 'HEADS:', heads
        commands.bundle(ui_, repo, out_file,
                        None, base=list(freenet_heads),
                        rev=heads)
    finally:
        ui_.popbuffer()
Ejemplo n.º 4
0
def _getbundle(repo, dest, **opts):
    """return a bundle containing changesets missing in "dest"

    The `opts` keyword-arguments are the same as the one accepted by the
    `bundle` command.

    The bundle is a returned as a single in-memory binary blob.
    """
    ui = repo.ui
    tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
    tmpfn = os.path.join(tmpdir, 'bundle')
    btype = ui.config('patchbomb', 'bundletype')
    if btype:
        opts['type'] = btype
    try:
        commands.bundle(ui, repo, tmpfn, dest, **opts)
        fp = open(tmpfn, 'rb')
        data = fp.read()
        fp.close()
        return data
    finally:
        try:
            os.unlink(tmpfn)
        except OSError:
            pass
        os.rmdir(tmpdir)
Ejemplo n.º 5
0
def _getbundle(repo, dest, **opts):
    """return a bundle containing changesets missing in "dest"

    The `opts` keyword-arguments are the same as the one accepted by the
    `bundle` command.

    The bundle is a returned as a single in-memory binary blob.
    """
    ui = repo.ui
    tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
    tmpfn = os.path.join(tmpdir, 'bundle')
    btype = ui.config('patchbomb', 'bundletype')
    if btype:
        opts['type'] = btype
    try:
        commands.bundle(ui, repo, tmpfn, dest, **opts)
        fp = open(tmpfn, 'rb')
        data = fp.read()
        fp.close()
        return data
    finally:
        try:
            os.unlink(tmpfn)
        except OSError:
            pass
        os.rmdir(tmpdir)
Ejemplo n.º 6
0
 def getbundle(dest):
     tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
     tmpfn = os.path.join(tmpdir, 'bundle')
     try:
         commands.bundle(ui, repo, tmpfn, dest, **opts)
         return open(tmpfn, 'rb').read()
     finally:
         try:
             os.unlink(tmpfn)
         except:
             pass
         os.rmdir(tmpdir)
Ejemplo n.º 7
0
 def getbundle(dest):
     tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
     tmpfn = os.path.join(tmpdir, 'bundle')
     try:
         commands.bundle(ui, repo, tmpfn, dest, **opts)
         return open(tmpfn, 'rb').read()
     finally:
         try:
             os.unlink(tmpfn)
         except:
             pass
         os.rmdir(tmpdir)
Ejemplo n.º 8
0
    def make_bundle(self, graph, version_table, index_pair, out_file=None):
        """ Create an hg bundle file corresponding to the edge in graph. """
        #print "INDEX_PAIR:", index_pair
        assert not index_pair is None
        self.graph = graph

        cached = self.get_cached_bundle(index_pair, out_file)
        if not cached is None:
            #print "make_bundle -- cache hit: ", index_pair
            return cached

        delete_out_file = out_file is None
        if out_file is None:
            out_file = make_temp_file(self.base_dir)
        try:

            parents, heads = get_rollup_bounds(
                self.graph,
                self.repo,
                index_pair[0] + 1,  # INCLUSIVE
                index_pair[1],
                version_table)

            # Hmmm... ok to suppress mercurial noise here.
            self.ui_.pushbuffer()
            try:
                #print 'PARENTS:', list(parents)
                #print 'HEADS:', list(heads)
                commands.bundle(self.ui_,
                                self.repo,
                                out_file,
                                None,
                                base=list(parents),
                                rev=list(heads))
            finally:
                self.ui_.popbuffer()

            if self.enabled:
                self.update_cache(index_pair, out_file)
            file_field = None
            if not delete_out_file:
                file_field = out_file
            return (os.path.getsize(out_file), file_field, index_pair)
        finally:
            if delete_out_file and os.path.exists(out_file):
                os.remove(out_file)
Ejemplo n.º 9
0
    def make_bundle(self, graph, version_table, index_pair, out_file=None):
        """ Create an hg bundle file corresponding to the edge in graph. """
        # print "INDEX_PAIR:", index_pair
        assert not index_pair is None
        self.graph = graph

        cached = self.get_cached_bundle(index_pair, out_file)
        if not cached is None:
            # print "make_bundle -- cache hit: ", index_pair
            return cached

        delete_out_file = out_file is None
        if out_file is None:
            out_file = make_temp_file(self.base_dir)
        try:

            parents, heads = get_rollup_bounds(
                self.graph, self.repo, index_pair[0] + 1, index_pair[1], version_table  # INCLUSIVE
            )

            # Hmmm... ok to suppress mercurial noise here.
            self.ui_.pushbuffer()
            try:
                # print 'PARENTS:', list(parents)
                # print 'HEADS:', list(heads)
                commands.bundle(self.ui_, self.repo, out_file, None, base=list(parents), rev=list(heads))
            finally:
                self.ui_.popbuffer()

            if self.enabled:
                self.update_cache(index_pair, out_file)
            file_field = None
            if not delete_out_file:
                file_field = out_file
            return (os.path.getsize(out_file), file_field, index_pair)
        finally:
            if delete_out_file and os.path.exists(out_file):
                os.remove(out_file)
Ejemplo n.º 10
0
def send_review(ui, repo, c, parentc, diff, parentdiff, opts):
    files = None
    if opts['attachbundle']:
        tmpfile = tempfile.NamedTemporaryFile(prefix='review_', suffix='.hgbundle', delete=False)
        tmpfile.close()
        if opts['old_server']:
            ui.status('postreview using old server compatibility mode (bundle format v1)\n')
            # request explicit 'v1' bundle format for our old creaky reviewboard server (running mercurial 2.0.x)
            # because it would be unable to read new 'v2' bundle format that mercurial 3.x uses
            bundle(ui, repo, tmpfile.name, dest=None, base=(parentc.rev(),), rev=(c.rev(),), type='bzip2-v1')
        else:
            bundle(ui, repo, tmpfile.name, dest=None, base=(parentc.rev(),), rev=(c.rev(),))

        f = open(tmpfile.name,'rb')
        files = {BUNDLE_ATTACHMENT_CAPTION: {'filename': tmpfile.name, 'content': f.read()}}
        f.close()
        os.remove(tmpfile.name)
    fields = createfields(ui, repo, c, parentc, opts)

    request_id = opts['existing']
    if request_id:
        update_review(request_id, ui, fields, diff, parentdiff, opts, files)
    else:
        request_id = new_review(ui, fields, diff, parentdiff,
                                   opts, files)

    request_url = '%s/%s/%s/' % (find_server(ui, opts), "r", request_id)

    if not request_url.startswith('http'):
        request_url = 'http://%s' % request_url

    msg = 'review request draft saved: %s\n'
    if opts['publish']:
        msg = 'review request published: %s\n'
    ui.status(msg % request_url)
    
    if ui.configbool('reviewboard', 'launch_webbrowser'):
        launch_webbrowser(ui, request_url)