def adjustphase(repo, tr, phase, node):
     # transaction argument added in Mercurial 3.2.
     try:
         phases.advanceboundary(repo, tr, phase, [node])
         phases.retractboundary(repo, tr, phase, [node])
     except TypeError:
         phases.advanceboundary(repo, phase, [node])
         phases.retractboundary(repo, phase, [node])
Example #2
0
 def adjustphase(repo, tr, phase, node):
     # transaction argument added in Mercurial 3.2.
     try:
         phases.advanceboundary(repo, tr, phase, [node])
         phases.retractboundary(repo, tr, phase, [node])
     except TypeError:
         phases.advanceboundary(repo, phase, [node])
         phases.retractboundary(repo, phase, [node])
Example #3
0
 def finish(self, repo, revs):
     # Manually trigger phase computation to ensure phasedefaults is
     # executed before we remove the patches.
     repo._phasecache
     patches = self._revpatches(repo, sorted(revs))
     qfinished = self._cleanup(patches, len(patches))
     if qfinished and repo.ui.configbool('mq', 'secret', False):
         # only use this logic when the secret option is added
         oldqbase = repo[qfinished[0]]
         tphase = repo.ui.config('phases', 'new-commit', phases.draft)
         if oldqbase.phase() > tphase and oldqbase.p1().phase() <= tphase:
             phases.advanceboundary(repo, tphase, qfinished)
Example #4
0
            newrev = _graft(op.repo, onto, rev)
            onto = op.repo[newrev]
            replacements[rev.node()] = onto.node()
            added.append(onto.node())
        _buildobsolete(replacements, bundle, op.repo)
    finally:
        try:
            if bundlefile:
                os.unlink(bundlefile)
        except OSError, e:
            if e.errno != errno.ENOENT:
                raise

    publishing = op.repo.ui.configbool('phases', 'publish', True)
    if publishing:
        phases.advanceboundary(op.repo, tr, phases.public, [added[-1]])

    p = lambda: tr.writepending() and op.repo.root or ""
    op.repo.hook("pretxnchangegroup", throw=True, pending=p, **hookargs)

    def runhooks():
        args = hookargs.copy()
        args['node'] = hex(added[0])
        op.repo.hook("changegroup", **args)
        for n in added:
            args = hookargs.copy()
            args['node'] = hex(n)
            op.repo.hook("incoming", **args)

    tr.addpostclose('serverrebase-cg-hooks',
                    lambda tr: op.repo._afterlock(runhooks))
Example #5
0
def bundle2rebase(op, part):
    '''unbundle a bundle2 containing a changegroup to rebase'''

    params = part.params

    bundlefile = None

    try: # guards bundlefile
        bundlefile = _makebundlefile(part)
        bundlepath = "bundle:%s+%s" % (op.repo.root, bundlefile)
        bundle = repository(op.repo.ui, bundlepath)

        # Allow running hooks on the new commits before we take the lock
        prelockrebaseargs = dict()
        prelockrebaseargs['source'] = 'push'
        prelockrebaseargs['bundle2'] = '1'
        prelockrebaseargs['node'] = scmutil.revsingle(bundle,
                                                      'min(bundle())').hex()
        prelockrebaseargs['hook_bundlepath'] = bundlefile
        op.repo.hook("prepushrebase", throw=True, **prelockrebaseargs)

        op.repo.ui.setconfig('pushrebase', pushrebasemarker, True)
        tr = op.gettransaction()
        hookargs = dict(tr.hookargs)

        # Recreate the bundle repo, since taking the lock in gettranscation()
        # may have caused it to become out of date.
        # (but grab a copy of the cache first)
        bundle = repository(op.repo.ui, bundlepath)

        # Preload the caches with data we already have. We need to make copies
        # here so that original repo caches don't get tainted with bundle
        # specific data.
        bundle.manifest._mancache = op.repo.manifest._mancache.copy()

        try:
            # onto is None means don't do rebasing
            onto = None
            ontoarg = params.get('onto', donotrebasemarker)
            if ontoarg != donotrebasemarker:
                onto = scmutil.revsingle(op.repo, ontoarg)
        except error.RepoLookupError:
            # Probably a new bookmark. Leave onto as None to not do any rebasing
            pass

        if not params['newhead']:
            if not op.repo.revs('%r and head()', params['onto']):
                raise error.Abort(_('rebase would create a new head on server'))

        if onto is None:
            maxcommonanc = list(bundle.set('max(parents(bundle()) - bundle())'))
            if not maxcommonanc:
                onto = op.repo[nullid]
            else:
                onto = maxcommonanc[0]

        revs, oldonto = _getrevs(bundle, onto)

        op.repo.hook("prechangegroup", **hookargs)

        mapping = {}

        # Seed the mapping with oldonto->onto
        mapping[oldonto.node()] = onto.node()

        replacements = {}
        added = []

        # Notify the user of what is being pushed
        plural = 's' if len(revs) > 1 else ''
        op.repo.ui.warn(_("pushing %s commit%s:\n") % (len(revs), plural))
        maxoutput = 10
        for i in range(0, min(len(revs), maxoutput)):
            firstline = bundle[revs[i]].description().split('\n')[0][:50]
            op.repo.ui.warn(("    %s  %s\n") % (revs[i], firstline))

        if len(revs) > maxoutput + 1:
            op.repo.ui.warn(("    ...\n"))
            firstline = bundle[revs[-1]].description().split('\n')[0][:50]
            op.repo.ui.warn(("    %s  %s\n") % (revs[-1], firstline))

        for rev in revs:
            newrev = _graft(op.repo, rev, mapping)

            new = op.repo[newrev]
            oldnode = rev.node()
            newnode = new.node()
            replacements[oldnode] = newnode
            mapping[oldnode] = newnode
            added.append(newnode)

            if 'node' not in tr.hookargs:
                tr.hookargs['node'] = hex(newnode)
            hookargs['node'] = hex(newnode)

        _buildobsolete(replacements, bundle, op.repo)
    finally:
        try:
            if bundlefile:
                os.unlink(bundlefile)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise

    publishing = op.repo.ui.configbool('phases', 'publish', True)
    if publishing:
        phases.advanceboundary(op.repo, tr, phases.public, [added[-1]])

    p = lambda: tr.writepending() and op.repo.root or ""
    op.repo.hook("pretxnchangegroup", throw=True, pending=p, **hookargs)

    def runhooks():
        args = hookargs.copy()
        args['node'] = hex(added[0])
        op.repo.hook("changegroup", **args)
        for n in added:
            args = hookargs.copy()
            args['node'] = hex(n)
            op.repo.hook("incoming", **args)

    tr.addpostclose('serverrebase-cg-hooks',
                    lambda tr: op.repo._afterlock(runhooks))

    _addpushbackparts(op, replacements)

    for k in replacements.keys():
        replacements[hex(k)] = hex(replacements[k])
    op.records.add(rebaseparttype, replacements)

    return 1
Example #6
0
def bundle2rebase(op, part):
    '''unbundle a bundle2 containing a changegroup to rebase'''

    params = part.params

    bundlefile = None
    bundle = None
    markerdate = util.makedate()

    try: # guards bundlefile
        bundlefile = _makebundlefile(part)
        bundlepath = "bundle:%s+%s" % (op.repo.root, bundlefile)
        bundle = _createbundlerepo(op, bundlepath)

        prepushrebasehooks(op, params, bundle, bundlefile)

        op.repo.ui.setconfig('pushrebase', pushrebasemarker, True)

        bundlerepocache, preontocache = prefetchcaches(op, params, bundle)

        # Create a cache of rename sources while we don't have the lock.
        renamesrccache = {bundle[r].node(): _getrenamesrcs(op, bundle[r])
                          for r in bundle.revs('bundle()')}

        # Opening the transaction takes the lock, so do it after prepushrebase
        # and after we've fetched all the cache information we'll need.
        tr = op.gettransaction()
        hookargs = dict(tr.hookargs)

        # Recreate the bundle repo, since taking the lock in gettransaction()
        # may have caused it to become out of date.
        # (but grab a copy of the cache first)
        bundle.close()
        bundle = _createbundlerepo(op, bundlepath)

        prefillcaches(op, bundle, bundlerepocache)

        onto = getontotarget(op, params, bundle)

        revs, oldonto = _getrevs(op, bundle, onto, renamesrccache)

        op.repo.hook("prechangegroup", **hookargs)

        printpushmessage(op, revs, bundle)

        # Prepopulate the revlog _cache with the original onto's fulltext. This
        # means reading the new onto's manifest will likely have a much shorter
        # delta chain to traverse.
        if preontocache:
            op.repo.manifestlog._revlog._cache = preontocache
            onto.manifest()

        # Perform the rebase + commit to the main repo
        added, replacements = runrebase(op, revs, oldonto, onto)

        markers = _buildobsolete(replacements, bundle, op.repo, markerdate)
    finally:
        try:
            if bundlefile:
                os.unlink(bundlefile)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
        if bundle:
            bundle.close()

    # Move public phase forward
    publishing = op.repo.ui.configbool('phases', 'publish', untrusted=True)
    if publishing:
        phasesmod.advanceboundary(op.repo, tr, phasesmod.public, [added[-1]])

    addfinalhooks(op, tr, hookargs, added)

    # Send new commits back to the client
    clientobsmarkerversions = [
        int(v) for v in params.get('obsmarkerversions', '').split('\0') if v]
    _addpushbackparts(op, replacements, markers, markerdate,
                      clientobsmarkerversions)

    for k in replacements.keys():
        replacements[hex(k)] = hex(replacements[k])
    op.records.add(rebaseparttype, replacements)

    return 1