コード例 #1
0
ファイル: histedit.py プロジェクト: CSCI-362-02-2015/RedTeam
def cleanupnode(ui, repo, name, nodes):
    """strip a group of nodes from the repository

    The set of node to strip may contains unknown nodes."""
    ui.debug('should strip %s nodes %s\n' %
             (name, ', '.join([node.short(n) for n in nodes])))
    lock = None
    try:
        lock = repo.lock()
        # do not let filtering get in the way of the cleanse
        # we should probably get rid of obsolescence marker created during the
        # histedit, but we currently do not have such information.
        repo = repo.unfiltered()
        # Find all nodes that need to be stripped
        # (we use %lr instead of %ln to silently ignore unknown items)
        nm = repo.changelog.nodemap
        nodes = sorted(n for n in nodes if n in nm)
        roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
        for c in roots:
            # We should process node in reverse order to strip tip most first.
            # but this trigger a bug in changegroup hook.
            # This would reduce bundle overhead
            repair.strip(ui, repo, c)
    finally:
        release(lock)
コード例 #2
0
ファイル: strip.py プロジェクト: Azult/containers-exercise
def strip(ui,
          repo,
          revs,
          update=True,
          backup="all",
          force=None,
          bookmark=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if (util.safehasattr(repo, 'mq') and p2 != nullid
                    and p2 in [x.node for x in repo.mq.applied]):
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write()

        repair.strip(ui, repo, revs, backup)

        marks = repo._bookmarks
        if bookmark:
            if bookmark == repo._bookmarkcurrent:
                bookmarks.unsetcurrent(repo)
            del marks[bookmark]
            marks.write()
            ui.write(_("bookmark '%s' deleted\n") % bookmark)
    finally:
        release(lock, wlock)
コード例 #3
0
ファイル: strip.py プロジェクト: areshero/ThirdWorldApp
def strip(ui, repo, revs, update=True, backup=True, force=None, bookmark=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if (util.safehasattr(repo, 'mq') and
                p2 != nullid
                and p2 in [x.node for x in repo.mq.applied]):
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write()

        repair.strip(ui, repo, revs, backup)

        marks = repo._bookmarks
        if bookmark:
            if bookmark == repo._bookmarkcurrent:
                bookmarks.unsetcurrent(repo)
            del marks[bookmark]
            marks.write()
            ui.write(_("bookmark '%s' deleted\n") % bookmark)
    finally:
        release(lock, wlock)
コード例 #4
0
        def kwcommitctx(self, ctx, error=False):
            wlock = lock = None
            try:
                wlock = self.wlock()
                lock = self.lock()
                # store and postpone commit hooks
                commithooks = {}
                for name, cmd in ui.configitems('hooks'):
                    if name.split('.', 1)[0] == 'commit':
                        commithooks[name] = cmd
                        ui.setconfig('hooks', name, None)
                if commithooks:
                    # store parents for commit hooks
                    p1, p2 = ctx.p1(), ctx.p2()
                    xp1, xp2 = p1.hex(), p2 and p2.hex() or ''

                n = super(kwrepo, self).commitctx(ctx, error)

                kwt.overwrite(n, True, None)
                if commithooks:
                    for name, cmd in commithooks.iteritems():
                        ui.setconfig('hooks', name, cmd)
                    self.hook('commit', node=n, parent1=xp1, parent2=xp2)
                return n
            finally:
                release(lock, wlock)
コード例 #5
0
def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if (util.safehasattr(repo, 'mq') and
                p2 != nullid
                and p2 in [x.node for x in repo.mq.applied]):
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write(repo.currenttransaction())

        repair.strip(ui, repo, revs, backup)

        repomarks = repo._bookmarks
        if bookmarks:
            with repo.transaction('strip') as tr:
                if repo._activebookmark in bookmarks:
                    bookmarksmod.deactivate(repo)
                for bookmark in bookmarks:
                    del repomarks[bookmark]
                repomarks.recordchange(tr)
            for bookmark in sorted(bookmarks):
                ui.write(_("bookmark '%s' deleted\n") % bookmark)
    finally:
        release(lock, wlock)
コード例 #6
0
ファイル: rebase.py プロジェクト: pierfort123/mercurial
def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None):
    """Commit the wd changes with parents p1 and p2. Reuse commit info from rev
    but also store useful information in extra.
    Return node of committed revision."""
    dsguard = cmdutil.dirstateguard(repo, "rebase")
    try:
        repo.setparents(repo[p1].node(), repo[p2].node())
        ctx = repo[rev]
        if commitmsg is None:
            commitmsg = ctx.description()
        extra = {"rebase_source": ctx.hex()}
        if extrafn:
            extrafn(ctx, extra)

        backup = repo.ui.backupconfig("phases", "new-commit")
        try:
            targetphase = max(ctx.phase(), phases.draft)
            repo.ui.setconfig("phases", "new-commit", targetphase, "rebase")
            # Commit might fail if unresolved files exist
            newnode = repo.commit(text=commitmsg, user=ctx.user(), date=ctx.date(), extra=extra, editor=editor)
        finally:
            repo.ui.restoreconfig(backup)

        repo.dirstate.setbranch(repo[newnode].branch())
        dsguard.close()
        return newnode
    finally:
        release(dsguard)
コード例 #7
0
ファイル: histedit.py プロジェクト: michalliu/MyCygwin
def histedit(ui, repo, *freeargs, **opts):
    """interactively edit changeset history

    This command edits changesets between ANCESTOR and the parent of
    the working directory.

    With --outgoing, this edits changesets not found in the
    destination repository. If URL of the destination is omitted, the
    'default-push' (or 'default') path will be used.

    For safety, this command is aborted, also if there are ambiguous
    outgoing revisions which may confuse users: for example, there are
    multiple branches containing outgoing revisions.

    Use "min(outgoing() and ::.)" or similar revset specification
    instead of --outgoing to specify edit target revision exactly in
    such ambiguous situation. See :hg:`help revsets` for detail about
    selecting revisions.

    Returns 0 on success, 1 if user intervention is required (not only
    for intentional "edit" command, but also for resolving unexpected
    conflicts).
    """
    state = histeditstate(repo)
    try:
        state.wlock = repo.wlock()
        state.lock = repo.lock()
        _histedit(ui, repo, state, *freeargs, **opts)
    finally:
        release(state.lock, state.wlock)
コード例 #8
0
def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None):
    '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
    but also store useful information in extra.
    Return node of committed revision.'''
    dsguard = cmdutil.dirstateguard(repo, 'rebase')
    try:
        repo.setparents(repo[p1].node(), repo[p2].node())
        ctx = repo[rev]
        if commitmsg is None:
            commitmsg = ctx.description()
        extra = {'rebase_source': ctx.hex()}
        if extrafn:
            extrafn(ctx, extra)

        backup = repo.ui.backupconfig('phases', 'new-commit')
        try:
            targetphase = max(ctx.phase(), phases.draft)
            repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
            # Commit might fail if unresolved files exist
            newnode = repo.commit(text=commitmsg, user=ctx.user(),
                                  date=ctx.date(), extra=extra, editor=editor)
        finally:
            repo.ui.restoreconfig(backup)

        repo.dirstate.setbranch(repo[newnode].branch())
        dsguard.close()
        return newnode
    finally:
        release(dsguard)
コード例 #9
0
def unshelveabort(ui, repo, state, opts):
    """subcommand that abort an in-progress unshelve"""
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)

        util.rename(repo.join('unshelverebasestate'),
                    repo.join('rebasestate'))
        try:
            rebase.rebase(ui, repo, **{
                'abort' : True
            })
        except Exception:
            util.rename(repo.join('rebasestate'),
                        repo.join('unshelverebasestate'))
            raise

        lock = repo.lock()

        mergefiles(ui, repo, state.wctx, state.pendingctx)

        repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
        shelvedstate.clear(repo)
        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
    finally:
        lockmod.release(lock, wlock)
コード例 #10
0
def unshelveabort(ui, repo, state, opts):
    """subcommand that abort an in-progress unshelve"""
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)

        util.rename(repo.join('unshelverebasestate'),
                    repo.join('rebasestate'))
        try:
            rebase.rebase(ui, repo, **{
                'abort' : True
            })
        except Exception:
            util.rename(repo.join('rebasestate'),
                        repo.join('unshelverebasestate'))
            raise

        lock = repo.lock()

        mergefiles(ui, repo, state.wctx, state.pendingctx)

        repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve')
        shelvedstate.clear(repo)
        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
    finally:
        lockmod.release(lock, wlock)
コード例 #11
0
ファイル: mq.py プロジェクト: peiyaoyao/intellij-community
 def apply(self, repo, series, list=False, update_status=True,
           strict=False, patchdir=None, merge=None, all_files=None,
           tobackup=None, keepchanges=False):
     wlock = lock = tr = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
         tr = repo.transaction("qpush")
         try:
             ret = self._apply(repo, series, list, update_status,
                               strict, patchdir, merge, all_files=all_files,
                               tobackup=tobackup, keepchanges=keepchanges)
             tr.close()
             self.savedirty()
             return ret
         except AbortNoCleanup:
             tr.close()
             self.savedirty()
             return 2, repo.dirstate.p1()
         except: # re-raises
             try:
                 tr.abort()
             finally:
                 repo.invalidate()
                 repo.dirstate.invalidate()
                 self.invalidate()
             raise
     finally:
         release(tr, lock, wlock)
         self.removeundo(repo)
コード例 #12
0
        def kwcommitctx(self, ctx, error=False):
            wlock = lock = None
            try:
                wlock = self.wlock()
                lock = self.lock()
                # store and postpone commit hooks
                commithooks = {}
                for name, cmd in ui.configitems('hooks'):
                    if name.split('.', 1)[0] == 'commit':
                        commithooks[name] = cmd
                        ui.setconfig('hooks', name, None)
                if commithooks:
                    # store parents for commit hooks
                    p1, p2 = ctx.p1(), ctx.p2()
                    xp1, xp2 = p1.hex(), p2 and p2.hex() or ''

                n = super(kwrepo, self).commitctx(ctx, error)

                kwt.overwrite(n, True, None)
                if commithooks:
                    for name, cmd in commithooks.iteritems():
                        ui.setconfig('hooks', name, cmd)
                    self.hook('commit', node=n, parent1=xp1, parent2=xp2)
                return n
            finally:
                release(lock, wlock)
コード例 #13
0
def _inhibitmarkers(repo, nodes):
    """add marker inhibitor for all obsolete revision under <nodes>

    Content of <nodes> and all mutable ancestors are considered. Marker for
    obsolete revision only are created.
    """
    if not _inhibitenabled(repo):
        return

    # we add (non public()) as a lower boundary to
    # - use the C code in 3.6 (no ancestors in C as this is written)
    # - restrict the search space. Otherwise, the ancestors can spend a lot of
    #   time iterating if you have a check very low in the repo. We do not need
    #   to iterate over tens of thousand of public revisions with higher
    #   revision number
    #
    # In addition, the revset logic could be made significantly smarter here.
    newinhibit = repo.revs('(not public())::%ln and obsolete()', nodes)
    if newinhibit:
        node = repo.changelog.node
        lock = tr = None
        try:
            lock = repo.lock()
            tr = repo.transaction('obsinhibit')
            repo._obsinhibit.update(node(r) for r in newinhibit)
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
            repo.invalidatevolatilesets()
            tr.close()
        finally:
            lockmod.release(tr, lock)
コード例 #14
0
ファイル: util.py プロジェクト: jgehrig/hg-git
def updatebookmarks(repo, changes, name='git_handler'):
    """abstract writing bookmarks for backwards compatibility"""
    bms = repo._bookmarks
    tr = lock = wlock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        tr = repo.transaction(name)
        if hgutil.safehasattr(bms, 'applychanges'):
            # applychanges was added in mercurial 4.3
            bms.applychanges(repo, tr, changes)
        else:
            for name, node in changes:
                if node is None:
                    del bms[name]
                else:
                    bms[name] = node
            if hgutil.safehasattr(bms, 'recordchange'):
                # recordchange was added in mercurial 3.2
                bms.recordchange(tr)
            else:
                bms.write()
        tr.close()
    finally:
        lockmod.release(tr, lock, wlock)
コード例 #15
0
ファイル: shelve.py プロジェクト: jordigh/mercurial-crew
def unshelveabort(ui, repo, state, opts):
    """subcommand that abort an in-progress unshelve"""
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)
        lock = repo.lock()
        merge.mergestate(repo).reset()
        if opts['keep']:
            repo.setparents(repo.dirstate.parents()[0])
        else:
            revertfiles = readshelvedfiles(repo, state.name)
            wctx = repo.parents()[0]
            cmdutil.revert(ui, repo, wctx, [wctx.node(), nullid],
                           *revertfiles, **{'no_backup': True})
            # fix up the weird dirstate states the merge left behind
            mf = wctx.manifest()
            dirstate = repo.dirstate
            for f in revertfiles:
                if f in mf:
                    dirstate.normallookup(f)
                else:
                    dirstate.drop(f)
            dirstate._pl = (wctx.node(), nullid)
            dirstate._dirty = True
        repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve')
        shelvedstate.clear(repo)
        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
    finally:
        lockmod.release(lock, wlock)
コード例 #16
0
ファイル: histedit.py プロジェクト: RayFerr000/PLTL
def histedit(ui, repo, *freeargs, **opts):
    """interactively edit changeset history

    This command edits changesets between ANCESTOR and the parent of
    the working directory.

    With --outgoing, this edits changesets not found in the
    destination repository. If URL of the destination is omitted, the
    'default-push' (or 'default') path will be used.

    For safety, this command is aborted, also if there are ambiguous
    outgoing revisions which may confuse users: for example, there are
    multiple branches containing outgoing revisions.

    Use "min(outgoing() and ::.)" or similar revset specification
    instead of --outgoing to specify edit target revision exactly in
    such ambiguous situation. See :hg:`help revsets` for detail about
    selecting revisions.

    Returns 0 on success, 1 if user intervention is required (not only
    for intentional "edit" command, but also for resolving unexpected
    conflicts).
    """
    state = histeditstate(repo)
    try:
        state.wlock = repo.wlock()
        state.lock = repo.lock()
        _histedit(ui, repo, state, *freeargs, **opts)
    finally:
        release(state.lock, state.wlock)
コード例 #17
0
ファイル: reset.py プロジェクト: davidshepherd7/dotfiles
def _deleteunreachable(repo, ctx):
    """Deletes all ancestor and descendant commits of the given revision that
    aren't reachable from another bookmark.
    """
    keepheads = "bookmark() + ."
    try:
        extensions.find('remotenames')
        keepheads += " + remotenames()"
    except KeyError:
        pass
    hiderevs = repo.revs('::%s - ::(%r)', ctx.rev(), keepheads)
    if hiderevs:
        lock = None
        try:
            lock = repo.lock()
            if _isobsstoreenabled(repo):
                markers = []
                for rev in hiderevs:
                    markers.append((repo[rev], ()))
                obsolete.createmarkers(repo, markers)
                repo.ui.status(_("%d changesets pruned\n") % len(hiderevs))
            else:
                repair.strip(repo.ui, repo,
                             [repo.changelog.node(r) for r in hiderevs])
        finally:
            lockmod.release(lock)
コード例 #18
0
ファイル: strip.py プロジェクト: Distrotech/mercurial
def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if (util.safehasattr(repo, 'mq') and
                p2 != nullid
                and p2 in [x.node for x in repo.mq.applied]):
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write(repo.currenttransaction())

        repair.strip(ui, repo, revs, backup)

        repomarks = repo._bookmarks
        if bookmarks:
            tr = None
            try:
                tr = repo.transaction('strip')
                if repo._activebookmark in bookmarks:
                    bookmarksmod.deactivate(repo)
                for bookmark in bookmarks:
                    del repomarks[bookmark]
                repomarks.recordchange(tr)
                tr.close()
                for bookmark in sorted(bookmarks):
                    ui.write(_("bookmark '%s' deleted\n") % bookmark)
            finally:
                release(tr)
    finally:
        release(lock, wlock)
コード例 #19
0
ファイル: rebase.py プロジェクト: CSCI-362-02-2015/RedTeam
def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None,
                 keepbranches=False):
    '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
    but also store useful information in extra.
    Return node of committed revision.'''
    dsguard = cmdutil.dirstateguard(repo, 'rebase')
    try:
        repo.setparents(repo[p1].node(), repo[p2].node())
        ctx = repo[rev]
        if commitmsg is None:
            commitmsg = ctx.description()
        keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
        extra = {'rebase_source': ctx.hex()}
        if extrafn:
            extrafn(ctx, extra)

        backup = repo.ui.backupconfig('phases', 'new-commit')
        try:
            targetphase = max(ctx.phase(), phases.draft)
            repo.ui.setconfig('phases', 'new-commit', targetphase, 'rebase')
            if keepbranch:
                repo.ui.setconfig('ui', 'allowemptycommit', True)
            # Commit might fail if unresolved files exist
            newnode = repo.commit(text=commitmsg, user=ctx.user(),
                                  date=ctx.date(), extra=extra, editor=editor)
        finally:
            repo.ui.restoreconfig(backup)

        repo.dirstate.setbranch(repo[newnode].branch())
        dsguard.close()
        return newnode
    finally:
        release(dsguard)
コード例 #20
0
ファイル: fbhistedit.py プロジェクト: davidshepherd7/dotfiles
        def run(self):
            state = self.state
            repo, ctxnode = state.repo, state.parentctxnode
            hg.update(repo, ctxnode)

            # release locks so the program can call hg and then relock.
            lock.release(state.lock, state.wlock)

            try:
                ctx = repo[ctxnode]
                shell = encoding.environ.get('SHELL', None)
                cmd = self.command
                if shell and self.repo.ui.config('fbhistedit',
                                                 'exec_in_user_shell'):
                    cmd = "%s -c -i %s" % (shell, quote(cmd))
                rc = repo.ui.system(cmd,  environ={'HGNODE': ctx.hex()},
                                    cwd=self.cwd, blockedtag='histedit_exec')
            except OSError as ose:
                raise error.InterventionRequired(
                    _("Cannot execute command '%s': %s") % (self.command, ose))
            finally:
                # relock the repository
                state.wlock = repo.wlock()
                state.lock = repo.lock()
                repo.invalidateall()

            if rc != 0:
                raise error.InterventionRequired(
                    _("Command '%s' failed with exit status %d") %
                    (self.command, rc))

            m, a, r, d = self.repo.status()[:4]
            if m or a or r or d:
                self.continuedirty()
            return self.continueclean()
コード例 #21
0
ファイル: histedit.py プロジェクト: CSCI-362-02-2015/RedTeam
def cleanupnode(ui, repo, name, nodes):
    """strip a group of nodes from the repository

    The set of node to strip may contains unknown nodes."""
    ui.debug('should strip %s nodes %s\n' %
             (name, ', '.join([node.short(n) for n in nodes])))
    lock = None
    try:
        lock = repo.lock()
        # do not let filtering get in the way of the cleanse
        # we should probably get rid of obsolescence marker created during the
        # histedit, but we currently do not have such information.
        repo = repo.unfiltered()
        # Find all nodes that need to be stripped
        # (we use %lr instead of %ln to silently ignore unknown items)
        nm = repo.changelog.nodemap
        nodes = sorted(n for n in nodes if n in nm)
        roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
        for c in roots:
            # We should process node in reverse order to strip tip most first.
            # but this trigger a bug in changegroup hook.
            # This would reduce bundle overhead
            repair.strip(ui, repo, c)
    finally:
        release(lock)
コード例 #22
0
def censor(ui, repo, path, rev='', tombstone='', **opts):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        return _docensor(ui, repo, path, rev, tombstone, **opts)
    finally:
        lockmod.release(lock, wlock)
コード例 #23
0
ファイル: censor.py プロジェクト: motlin/cyg
def censor(ui, repo, path, rev='', tombstone='', **opts):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        return _docensor(ui, repo, path, rev, tombstone, **opts)
    finally:
        lockmod.release(lock, wlock)
コード例 #24
0
def createcmd(ui, repo, pats, opts):
    """subcommand that creates a new shelve"""
    wlock = repo.wlock()
    try:
        cmdutil.checkunfinished(repo)
        return _docreatecmd(ui, repo, pats, opts)
    finally:
        lockmod.release(wlock)
コード例 #25
0
ファイル: test-lock.py プロジェクト: CSCI-362-02-2015/RedTeam
 def testlock(self):
     state = teststate(self, tempfile.mkdtemp(dir=os.getcwd()))
     lock = state.makelock()
     state.assertacquirecalled(True)
     lock.release()
     state.assertreleasecalled(True)
     state.assertpostreleasecalled(True)
     state.assertlockexists(False)
コード例 #26
0
 def testlock(self):
     state = teststate(self, tempfile.mkdtemp(dir=os.getcwd()))
     lock = state.makelock()
     state.assertacquirecalled(True)
     lock.release()
     state.assertreleasecalled(True)
     state.assertpostreleasecalled(True)
     state.assertlockexists(False)
コード例 #27
0
ファイル: shelve.py プロジェクト: Distrotech/mercurial
def createcmd(ui, repo, pats, opts):
    """subcommand that creates a new shelve"""
    wlock = repo.wlock()
    try:
        cmdutil.checkunfinished(repo)
        return _docreatecmd(ui, repo, pats, opts)
    finally:
        lockmod.release(wlock)
コード例 #28
0
ファイル: transplant.py プロジェクト: Distrotech/mercurial
def transplant(ui, repo, *revs, **opts):
    '''transplant changesets from another branch

    Selected changesets will be applied on top of the current working
    directory with the log of the original changeset. The changesets
    are copied and will thus appear twice in the history with different
    identities.

    Consider using the graft command if everything is inside the same
    repository - it will use merges and will usually give a better result.
    Use the rebase extension if the changesets are unpublished and you want
    to move them instead of copying them.

    If --log is specified, log messages will have a comment appended
    of the form::

      (transplanted from CHANGESETHASH)

    You can rewrite the changelog message with the --filter option.
    Its argument will be invoked with the current changelog message as
    $1 and the patch as $2.

    --source/-s specifies another repository to use for selecting changesets,
    just as if it temporarily had been pulled.
    If --branch/-b is specified, these revisions will be used as
    heads when deciding which changesets to transplant, just as if only
    these revisions had been pulled.
    If --all/-a is specified, all the revisions up to the heads specified
    with --branch will be transplanted.

    Example:

    - transplant all changes up to REV on top of your current revision::

        hg transplant --branch REV --all

    You can optionally mark selected transplanted changesets as merge
    changesets. You will not be prompted to transplant any ancestors
    of a merged transplant, and you can merge descendants of them
    normally instead of transplanting them.

    Merge changesets may be transplanted directly by specifying the
    proper parent changeset by calling :hg:`transplant --parent`.

    If no merges or revisions are provided, :hg:`transplant` will
    start an interactive changeset browser.

    If a changeset application fails, you can fix the merge by hand
    and then resume where you left off by calling :hg:`transplant
    --continue/-c`.
    '''
    wlock = None
    try:
        wlock = repo.wlock()
        return _dotransplant(ui, repo, *revs, **opts)
    finally:
        lockmod.release(wlock)
コード例 #29
0
ファイル: transplant.py プロジェクト: shiftwinting/mercurial
def transplant(ui, repo, *revs, **opts):
    '''transplant changesets from another branch

    Selected changesets will be applied on top of the current working
    directory with the log of the original changeset. The changesets
    are copied and will thus appear twice in the history with different
    identities.

    Consider using the graft command if everything is inside the same
    repository - it will use merges and will usually give a better result.
    Use the rebase extension if the changesets are unpublished and you want
    to move them instead of copying them.

    If --log is specified, log messages will have a comment appended
    of the form::

      (transplanted from CHANGESETHASH)

    You can rewrite the changelog message with the --filter option.
    Its argument will be invoked with the current changelog message as
    $1 and the patch as $2.

    --source/-s specifies another repository to use for selecting changesets,
    just as if it temporarily had been pulled.
    If --branch/-b is specified, these revisions will be used as
    heads when deciding which changesets to transplant, just as if only
    these revisions had been pulled.
    If --all/-a is specified, all the revisions up to the heads specified
    with --branch will be transplanted.

    Example:

    - transplant all changes up to REV on top of your current revision::

        hg transplant --branch REV --all

    You can optionally mark selected transplanted changesets as merge
    changesets. You will not be prompted to transplant any ancestors
    of a merged transplant, and you can merge descendants of them
    normally instead of transplanting them.

    Merge changesets may be transplanted directly by specifying the
    proper parent changeset by calling :hg:`transplant --parent`.

    If no merges or revisions are provided, :hg:`transplant` will
    start an interactive changeset browser.

    If a changeset application fails, you can fix the merge by hand
    and then resume where you left off by calling :hg:`transplant
    --continue/-c`.
    '''
    wlock = None
    try:
        wlock = repo.wlock()
        return _dotransplant(ui, repo, *revs, **opts)
    finally:
        lockmod.release(wlock)
コード例 #30
0
 def kwcommitctx(self, ctx, error=False):
     wlock = lock = None
     try:
         wlock = self.wlock()
         lock = self.lock()
         n = super(kwrepo, self).commitctx(ctx, error)
         kwt.overwrite(n, True, None)
         return n
     finally:
         release(lock, wlock)
コード例 #31
0
ファイル: keyword.py プロジェクト: yangdy-buji/idea-community
 def kwcommitctx(self, ctx, error=False):
     wlock = lock = None
     try:
         wlock = self.wlock()
         lock = self.lock()
         n = super(kwrepo, self).commitctx(ctx, error)
         kwt.overwrite(n, True, None)
         return n
     finally:
         release(lock, wlock)
コード例 #32
0
def cleanupcmd(ui, repo):
    """subcommand that deletes all shelves"""

    wlock = None
    try:
        wlock = repo.wlock()
        for (name, _) in repo.vfs.readdir('shelved'):
            suffix = name.rsplit('.', 1)[-1]
            if suffix in ('hg', 'files', 'patch'):
                shelvedfile(repo, name).unlink()
    finally:
        lockmod.release(wlock)
コード例 #33
0
def cleanupcmd(ui, repo):
    """subcommand that deletes all shelves"""

    wlock = None
    try:
        wlock = repo.wlock()
        for (name, _) in repo.vfs.readdir('shelved'):
            suffix = name.rsplit('.', 1)[-1]
            if suffix in ('hg', 'files', 'patch'):
                shelvedfile(repo, name).unlink()
    finally:
        lockmod.release(wlock)
コード例 #34
0
def _createmarkers(orig, repo, relations, flag=0, date=None, metadata=None):
    """wrap markers create to make sure we de-inhibit target nodes"""
    # wrapping transactio to unify the one in each function
    lock = tr = None
    try:
        lock = repo.lock()
        tr = repo.transaction('add-obsolescence-marker')
        orig(repo, relations, flag, date, metadata)
        precs = (r[0].node() for r in relations)
        _deinhibitmarkers(repo, precs)
        tr.close()
    finally:
        lockmod.release(tr, lock)
コード例 #35
0
    def testinheritcheck(self):
        d = tempfile.mkdtemp(dir=os.getcwd())
        state = teststate(self, d)
        def check():
            raise error.LockInheritanceContractViolation('check failed')
        lock = state.makelock(inheritchecker=check)
        state.assertacquirecalled(True)

        with self.assertRaises(error.LockInheritanceContractViolation):
            with lock.inherit():
                pass

        lock.release()
コード例 #36
0
ファイル: rebase.py プロジェクト: CSCI-362-02-2015/RedTeam
def pullrebase(orig, ui, repo, *args, **opts):
    'Call rebase after pull if the latter has been invoked with --rebase'
    ret = None
    if opts.get('rebase'):
        wlock = lock = None
        try:
            wlock = repo.wlock()
            lock = repo.lock()
            if opts.get('update'):
                del opts['update']
                ui.debug('--update and --rebase are not compatible, ignoring '
                         'the update flag\n')

            movemarkfrom = repo['.'].node()
            revsprepull = len(repo)
            origpostincoming = commands.postincoming
            def _dummy(*args, **kwargs):
                pass
            commands.postincoming = _dummy
            try:
                ret = orig(ui, repo, *args, **opts)
            finally:
                commands.postincoming = origpostincoming
            revspostpull = len(repo)
            if revspostpull > revsprepull:
                # --rev option from pull conflict with rebase own --rev
                # dropping it
                if 'rev' in opts:
                    del opts['rev']
                # positional argument from pull conflicts with rebase's own
                # --source.
                if 'source' in opts:
                    del opts['source']
                rebase(ui, repo, **opts)
                branch = repo[None].branch()
                dest = repo[branch].rev()
                if dest != repo['.'].rev():
                    # there was nothing to rebase we force an update
                    hg.update(repo, dest)
                    if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
                        ui.status(_("updating bookmark %s\n")
                                  % repo._activebookmark)
        finally:
            release(lock, wlock)
    else:
        if opts.get('tool'):
            raise error.Abort(_('--tool can only be used with --rebase'))
        ret = orig(ui, repo, *args, **opts)

    return ret
コード例 #37
0
ファイル: shelve.py プロジェクト: pierfort123/mercurial
def deletecmd(ui, repo, pats):
    """subcommand that deletes a specific shelve"""
    if not pats:
        raise util.Abort(_('no shelved changes specified!'))
    wlock = repo.wlock()
    try:
        for name in pats:
            for suffix in 'hg patch'.split():
                shelvedfile(repo, name, suffix).unlink()
    except OSError as err:
        if err.errno != errno.ENOENT:
            raise
        raise util.Abort(_("shelved change '%s' not found") % name)
    finally:
        lockmod.release(wlock)
コード例 #38
0
ファイル: test-lock.py プロジェクト: CSCI-362-02-2015/RedTeam
    def testinheritcheck(self):
        d = tempfile.mkdtemp(dir=os.getcwd())
        state = teststate(self, d)
        def check():
            raise error.LockInheritanceContractViolation('check failed')
        lock = state.makelock(inheritchecker=check)
        state.assertacquirecalled(True)

        def tryinherit():
            with lock.inherit():
                pass

        self.assertRaises(error.LockInheritanceContractViolation, tryinherit)

        lock.release()
コード例 #39
0
ファイル: mq.py プロジェクト: peiyaoyao/intellij-community
    def strip(self, repo, revs, update=True, backup="all", force=None):
        wlock = lock = None
        try:
            wlock = repo.wlock()
            lock = repo.lock()

            if update:
                self.checklocalchanges(repo, force=force, refresh=False)
                urev = self.qparents(repo, revs[0])
                hg.clean(repo, urev)
                repo.dirstate.write()

            repair.strip(self.ui, repo, revs, backup)
        finally:
            release(lock, wlock)
コード例 #40
0
ファイル: prune.py プロジェクト: davidshepherd7/dotfiles
def _deletebookmark(repo, repomarks, bookmarks):
    wlock = lock = tr = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        tr = repo.transaction('prune')
        changes = []
        for bookmark in bookmarks:
            changes.append((bookmark, None)) # delete the bookmark
        repomarks.applychanges(repo, tr, changes)
        tr.close()
        for bookmark in sorted(bookmarks):
            repo.ui.write(_("bookmark '%s' deleted\n") % bookmark)
    finally:
        lockmod.release(tr, lock, wlock)
コード例 #41
0
ファイル: util.py プロジェクト: schacon/hg-git
def recordbookmarks(repo, bms, name='git_handler'):
    """abstract writing bookmarks for backwards compatibility"""
    tr = lock = wlock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        tr = repo.transaction(name)
        if hgutil.safehasattr(bms, 'recordchange'):
            # recordchange was added in mercurial 3.2
            bms.recordchange(tr)
        else:
            bms.write()
        tr.close()
    finally:
        lockmod.release(tr, lock, wlock)
コード例 #42
0
ファイル: shelve.py プロジェクト: pierfort123/mercurial
def deletecmd(ui, repo, pats):
    """subcommand that deletes a specific shelve"""
    if not pats:
        raise util.Abort(_('no shelved changes specified!'))
    wlock = repo.wlock()
    try:
        for name in pats:
            for suffix in 'hg patch'.split():
                shelvedfile(repo, name, suffix).unlink()
    except OSError as err:
        if err.errno != errno.ENOENT:
            raise
        raise util.Abort(_("shelved change '%s' not found") % name)
    finally:
        lockmod.release(wlock)
コード例 #43
0
ファイル: util.py プロジェクト: termim/hg-git
def recordbookmarks(repo, bms, name='git_handler'):
    """abstract writing bookmarks for backwards compatibility"""
    tr = lock = wlock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        tr = repo.transaction(name)
        if hgutil.safehasattr(bms, 'recordchange'):
            # recordchange was added in mercurial 3.2
            bms.recordchange(tr)
        else:
            bms.write()
        tr.close()
    finally:
        lockmod.release(tr, lock, wlock)
コード例 #44
0
ファイル: hg.py プロジェクト: xunfeng1980/intellij-community
 def putbookmarks(self, updatedbookmark):
     if not len(updatedbookmark):
         return
     wlock = lock = tr = None
     try:
         wlock = self.repo.wlock()
         lock = self.repo.lock()
         tr = self.repo.transaction(b'bookmark')
         self.ui.status(_(b"updating bookmarks\n"))
         destmarks = self.repo._bookmarks
         changes = [(bookmark, bin(updatedbookmark[bookmark]))
                    for bookmark in updatedbookmark]
         destmarks.applychanges(self.repo, tr, changes)
         tr.close()
     finally:
         lockmod.release(lock, wlock, tr)
コード例 #45
0
 def putbookmarks(self, updatedbookmark):
     if not len(updatedbookmark):
         return
     wlock = lock = tr = None
     try:
         wlock = self.repo.wlock()
         lock = self.repo.lock()
         tr = self.repo.transaction('bookmark')
         self.ui.status(_("updating bookmarks\n"))
         destmarks = self.repo._bookmarks
         for bookmark in updatedbookmark:
             destmarks[bookmark] = bin(updatedbookmark[bookmark])
         destmarks.recordchange(tr)
         tr.close()
     finally:
         lockmod.release(lock, wlock, tr)
コード例 #46
0
def _kwfwrite(ui, repo, expand, *pats, **opts):
    '''Selects files and passes them to kwtemplater.overwrite.'''
    if repo.dirstate.parents()[1] != nullid:
        raise util.Abort(_('outstanding uncommitted merge'))
    kwt = kwtools['templater']
    status = _status(ui, repo, kwt, *pats, **opts)
    modified, added, removed, deleted = status[:4]
    if modified or added or removed or deleted:
        raise util.Abort(_('outstanding uncommitted changes'))
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        kwt.overwrite(None, expand, status[6])
    finally:
        release(lock, wlock)
コード例 #47
0
ファイル: keyword.py プロジェクト: yangdy-buji/idea-community
def _kwfwrite(ui, repo, expand, *pats, **opts):
    '''Selects files and passes them to kwtemplater.overwrite.'''
    if repo.dirstate.parents()[1] != nullid:
        raise util.Abort(_('outstanding uncommitted merge'))
    kwt = kwtools['templater']
    status = _status(ui, repo, kwt, *pats, **opts)
    modified, added, removed, deleted = status[:4]
    if modified or added or removed or deleted:
        raise util.Abort(_('outstanding uncommitted changes'))
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        kwt.overwrite(None, expand, status[6])
    finally:
        release(lock, wlock)
コード例 #48
0
ファイル: hg.py プロジェクト: cmjonze/mercurial
 def putbookmarks(self, updatedbookmark):
     if not len(updatedbookmark):
         return
     wlock = lock = tr = None
     try:
         wlock = self.repo.wlock()
         lock = self.repo.lock()
         tr = self.repo.transaction('bookmark')
         self.ui.status(_("updating bookmarks\n"))
         destmarks = self.repo._bookmarks
         for bookmark in updatedbookmark:
             destmarks[bookmark] = nodemod.bin(updatedbookmark[bookmark])
         destmarks.recordchange(tr)
         tr.close()
     finally:
         lockmod.release(lock, wlock, tr)
コード例 #49
0
def pullrebase(orig, ui, repo, *args, **opts):
    'Call rebase after pull if the latter has been invoked with --rebase'
    if opts.get('rebase'):
        wlock = lock = None
        try:
            wlock = repo.wlock()
            lock = repo.lock()
            if opts.get('update'):
                del opts['update']
                ui.debug('--update and --rebase are not compatible, ignoring '
                         'the update flag\n')

            movemarkfrom = repo['.'].node()
            revsprepull = len(repo)
            origpostincoming = commands.postincoming
            def _dummy(*args, **kwargs):
                pass
            commands.postincoming = _dummy
            try:
                orig(ui, repo, *args, **opts)
            finally:
                commands.postincoming = origpostincoming
            revspostpull = len(repo)
            if revspostpull > revsprepull:
                # --rev option from pull conflict with rebase own --rev
                # dropping it
                if 'rev' in opts:
                    del opts['rev']
                # positional argument from pull conflicts with rebase's own
                # --source.
                if 'source' in opts:
                    del opts['source']
                rebase(ui, repo, **opts)
                branch = repo[None].branch()
                dest = repo[branch].rev()
                if dest != repo['.'].rev():
                    # there was nothing to rebase we force an update
                    hg.update(repo, dest)
                    if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
                        ui.status(_("updating bookmark %s\n")
                                  % repo._activebookmark)
        finally:
            release(lock, wlock)
    else:
        if opts.get('tool'):
            raise util.Abort(_('--tool can only be used with --rebase'))
        orig(ui, repo, *args, **opts)
コード例 #50
0
ファイル: strip.py プロジェクト: jordigh/mercurial-crew
def strip(ui, repo, revs, update=True, backup="all", force=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if p2 != nullid and p2 in [x.node for x in repo.mq.applied]:
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write()

        repair.strip(ui, repo, revs, backup)
    finally:
        release(lock, wlock)
コード例 #51
0
def sign(ui, repo, *revs, **opts):
    """add a signature for the current or given revision

    If no revision is given, the parent of the working directory is used,
    or tip if no revision is checked out.

    The ``gpg.cmd`` config setting can be used to specify the command
    to run. A default key can be specified with ``gpg.key``.

    See :hg:`help dates` for a list of formats valid for -d/--date.
    """
    wlock = None
    try:
        wlock = repo.wlock()
        return _dosign(ui, repo, *revs, **opts)
    finally:
        lockmod.release(wlock)
コード例 #52
0
ファイル: gpg.py プロジェクト: Distrotech/mercurial
def sign(ui, repo, *revs, **opts):
    """add a signature for the current or given revision

    If no revision is given, the parent of the working directory is used,
    or tip if no revision is checked out.

    The ``gpg.cmd`` config setting can be used to specify the command
    to run. A default key can be specified with ``gpg.key``.

    See :hg:`help dates` for a list of formats valid for -d/--date.
    """
    wlock = None
    try:
        wlock = repo.wlock()
        return _dosign(ui, repo, *revs, **opts)
    finally:
        lockmod.release(wlock)
コード例 #53
0
    def testlockfork(self):
        state = teststate(self, tempfile.mkdtemp(dir=os.getcwd()))
        lock = state.makelock()
        state.assertacquirecalled(True)

        # fake a fork
        forklock = copy.deepcopy(lock)
        forklock._pidoffset = 1
        forklock.release()
        state.assertreleasecalled(False)
        state.assertpostreleasecalled(False)
        state.assertlockexists(True)

        # release the actual lock
        lock.release()
        state.assertreleasecalled(True)
        state.assertpostreleasecalled(True)
        state.assertlockexists(False)
コード例 #54
0
    def testrecursivelock(self):
        state = teststate(self, tempfile.mkdtemp(dir=os.getcwd()))
        lock = state.makelock()
        state.assertacquirecalled(True)

        state.resetacquirefn()
        lock.lock()
        # recursive lock should not call acquirefn again
        state.assertacquirecalled(False)

        lock.release() # brings lock refcount down from 2 to 1
        state.assertreleasecalled(False)
        state.assertpostreleasecalled(False)
        state.assertlockexists(True)

        lock.release() # releases the lock
        state.assertreleasecalled(True)
        state.assertpostreleasecalled(True)
        state.assertlockexists(False)
コード例 #55
0
ファイル: strip.py プロジェクト: sillsdev/Mercurial4Chorus
def strip(ui, repo, revs, update=True, backup="all", force=None):
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()

        if update:
            checklocalchanges(repo, force=force)
            urev, p2 = repo.changelog.parents(revs[0])
            if (util.safehasattr(repo, 'mq') and
                p2 != nullid
                and p2 in [x.node for x in repo.mq.applied]):
                urev = p2
            hg.clean(repo, urev)
            repo.dirstate.write()

        repair.strip(ui, repo, revs, backup)
    finally:
        release(lock, wlock)
コード例 #56
0
def _update(orig, ui, repo, *args, **kwargs):
    """
    When moving to a commit we want to inhibit any obsolete commit affecting
    the changeset we are updating to. In other words we don't want any visible
    commit to be obsolete.
    """
    wlock = None
    try:
        # Evolve is running a hook on lock release to display a warning message
        # if the workind dir's parent is obsolete.
        # We take the lock here to make sure that we inhibit the parent before
        # that hook get a chance to run.
        wlock = repo.wlock()
        res = orig(ui, repo, *args, **kwargs)
        newhead = repo['.'].node()
        _inhibitmarkers(repo, [newhead])
        return res
    finally:
        lockmod.release(wlock)
コード例 #57
0
ファイル: sync.py プロジェクト: noman798/system
    def dosync(self):
        """pull changes from a remote repository, merge new changes if needed.

        This finds all changes from the repository at the specified path
        or URL and adds them to the local repository.

        If the pulled changes add a new branch head, the head is
        automatically merged, and the result of the merge is committed.
        Otherwise, the working directory is updated to include the new
        changes.

        When a merge is needed, the working directory is first updated to
        the newly pulled changes. Local changes are then merged into the
        pulled changes. To switch the merge order, use --switch-parent.

        See :hg:`help dates` for a list of formats valid for -d/--date.

        Returns 0 on success.
        """

        initialrevision, p2 = self.repo.dirstate.parents()

        if p2 != nullid:
            raise util.Abort(_('outstanding uncommitted merge'))

        wlock = lock = None
        try:
            wlock = self.repo.wlock()
            lock = self.repo.lock()

            self.dopull()

            self.raiseifuncleanstatus()

            self.updateormerge(initialrevision)

            self.push()

            self.ui.status('sync complete\n')


        finally:
            release(lock, wlock)
コード例 #58
0
def unshelvecontinue(ui, repo, state, opts):
    """subcommand to continue an in-progress unshelve"""
    # We're finishing off a merge. First parent is our original
    # parent, second is the temporary "fake" commit we're unshelving.
    wlock = repo.wlock()
    lock = None
    try:
        checkparents(repo, state)
        ms = merge.mergestate(repo)
        if [f for f in ms if ms[f] == 'u']:
            raise util.Abort(
                _("unresolved conflicts, can't continue"),
                hint=_("see 'hg resolve', then 'hg unshelve --continue'"))

        lock = repo.lock()

        util.rename(repo.join('unshelverebasestate'),
                    repo.join('rebasestate'))
        try:
            rebase.rebase(ui, repo, **{
                'continue' : True
            })
        except Exception:
            util.rename(repo.join('rebasestate'),
                        repo.join('unshelverebasestate'))
            raise

        shelvectx = repo['tip']
        if not shelvectx in state.pendingctx.children():
            # rebase was a no-op, so it produced no child commit
            shelvectx = state.pendingctx
        else:
            # only strip the shelvectx if the rebase produced it
            state.stripnodes.append(shelvectx.node())

        mergefiles(ui, repo, state.wctx, shelvectx)

        repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
        shelvedstate.clear(repo)
        unshelvecleanup(ui, repo, state.name, opts)
        ui.status(_("unshelve of '%s' complete\n") % state.name)
    finally:
        lockmod.release(lock, wlock)