2 files changed, 0 insertions(+), 170 deletions(-)
R gitlikebookmarks.py =>
R tests/test-gitlikebookmarks.t =>
@@ 1,74 0,0 @@
-# gitlikebookmarks.py - add git like behavior for bookmarks
-#
-# Copyright 2015 Facebook, Inc.
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-"""add git like behavior for bookmarks: only move the active bookmark
-
-Add a -x specified to several commands. When the -x flag is specied, the
-commands only allow the active bookmark to move.
-"""
-
-from mercurial import extensions
-from mercurial import bookmarks
-from mercurial import util
-from mercurial.i18n import _
-
-gitlikebookmarkscommands = (
- # module name, command name
- ('rebase', 'rebase'),
- ('histedit', 'histedit'),
-)
-def _bookmarkwrite(orig, bkmstoreinst, *args, **kwargs):
- repo = bkmstoreinst._repo
- activebook = None
- bookmarksbefore = None
-
- if util.safehasattr(bkmstoreinst, "oldactivebookmark"):
- activebook = bkmstoreinst.oldactivebookmark
- bookmarksbefore = bkmstoreinst.oldbookmarks
-
- if activebook is not None:
- override = []
- for book in bkmstoreinst:
- if book == activebook:
- continue
- override.append(book)
- for k in override:
- if k in bookmarksbefore:
- bkmstoreinst[k] = bookmarksbefore[k]
- if repo._activebookmark != activebook:
- bookmarks.activate(repo, activebook)
-
- # XXX will be an issue with chg, -x will persist accross commands
- # Possible fixes:
- # 1) setting activebook to None here would only work
- # for commands with a single transaction (we have no guarantee of that)
- # 2) put all this code in _wrapfn and wrap the call to orig(...) in a
- # transaction but it will rollback if rebase/histedit has conflicts (not
- # intended behavior as we want to leave the conflicts in the workdir)
- return orig(bkmstoreinst, *args, **kwargs)
-
-def _wrapfn(orig, ui, repo, *args, **kwargs):
- # Normal behavior unless -x is specified
- if not kwargs.get('stickybookmark'):
- return orig(ui, repo, *args, **kwargs)
- repo._bookmarks.oldactivebookmark = repo._bookmarks.active
- repo._bookmarks.oldbookmarks = repo._bookmarks.copy()
- return orig(ui, repo, *args, **kwargs)
-
-def extsetup(ui):
- extensions.wrapfunction(bookmarks.bmstore, '_write', _bookmarkwrite)
- for module, fn in gitlikebookmarkscommands:
- try:
- ext = extensions.find(module)
- if ext:
- entry = extensions.wrapcommand(ext.cmdtable, fn, _wrapfn)
- entry[1].append(('x','stickybookmark', None,
- _('only allow the active bookmark to move'
- ' during the operation')))
- except KeyError:
- # Extension not present
- pass
@@ 1,96 0,0 @@
- $ $PYTHON -c 'import evolve' || exit 80
- $ cat >> $HGRCPATH << EOF
- > [extensions]
- > gitlikebookmarks=$TESTDIR/../gitlikebookmarks.py
- > rebase=
- > evolve=
- > inhibit=
- > directaccess=
- > [experimental]
- > evolution=createmarkers
- > EOF
- $ mkcommit() {
- > echo "$1" > "$1"
- > hg add "$1"
- > echo "add $1" > msg
- > echo "" >> msg
- > [ -z "$2" ] || echo "Differential Revision: https://phabricator.fb.com/D$2" >> msg
- > hg ci -l msg
- > }
-
- $ hg init repo
- $ cd repo
- $ mkcommit _a
- $ mkcommit _b
- $ hg up "desc(_a)"
- 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
- $ mkcommit _c
- created new head
- $ hg book first_bookmark
- $ hg book second_bookmark
- $ mkcommit _d
- $ hg log -G
- @ changeset: 3:3d974c2713ca
- | bookmark: second_bookmark
- | tag: tip
- | user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _d
- |
- o changeset: 2:1db8f42448cc
- | bookmark: first_bookmark
- | parent: 0:135f39f4bd78
- | user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _c
- |
- | o changeset: 1:37445b16603b
- |/ user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _b
- |
- o changeset: 0:135f39f4bd78
- user: test
- date: Thu Jan 01 00:00:00 1970 +0000
- summary: add _a
-
- $ hg bookmarks
- first_bookmark 2:1db8f42448cc
- * second_bookmark 3:3d974c2713ca
- $ hg rebase -s "desc(_c)" -d "desc(_b)" -x
- rebasing 2:1db8f42448cc "add _c" (first_bookmark)
- rebasing 3:3d974c2713ca "add _d" (tip second_bookmark)
- $ hg log -G
- @ changeset: 5:15f1a0e15dd8
- | bookmark: second_bookmark
- | tag: tip
- | user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _d
- |
- o changeset: 4:da71b5c6dbab
- | parent: 1:37445b16603b
- | user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _c
- |
- | o changeset: 2:1db8f42448cc
- | | bookmark: first_bookmark
- | | parent: 0:135f39f4bd78
- | | user: test
- | | date: Thu Jan 01 00:00:00 1970 +0000
- | | summary: add _c
- | |
- o | changeset: 1:37445b16603b
- |/ user: test
- | date: Thu Jan 01 00:00:00 1970 +0000
- | summary: add _b
- |
- o changeset: 0:135f39f4bd78
- user: test
- date: Thu Jan 01 00:00:00 1970 +0000
- summary: add _a
-
- $ hg bookmarks
- first_bookmark 2:1db8f42448cc
- * second_bookmark 5:15f1a0e15dd8