[PATCH 1 of 2] remotenames: record bookmark changes in the journal
Martijn Pieters
mj at zopatista.com
Fri Jul 1 11:57:47 UTC 2016
# HG changeset patch
# User Martijn Pieters <mjpieters at fb.com>
# Date 1467374115 -3600
# Fri Jul 01 12:55:15 2016 +0100
# Node ID 765689026f562a92b8eb58f4b4fad28cbbd4009b
# Parent 183d5b47f7472b839a96e7be735bb7fbf8068969
remotenames: record bookmark changes in the journal
Any changed remote names are logged in the journal so users can track where the
bookmark pointed to before.
diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -39,10 +39,13 @@
from mercurial import url
from mercurial import util
from mercurial.i18n import _
-from mercurial.node import hex, short, bin
+from mercurial.node import hex, short, bin, nullid
from hgext import schemes
from hgext.convert import hg as converthg
+# namespace to use when recording an hg journal entry
+journalremotebookmarktype = 'remotebookmark'
+
def exbookcalcupdate(orig, ui, repo, checkout):
'''Return a tuple (targetrev, movemarkfrom) indicating the rev to
check out and where to move the active bookmark from, if needed.'''
@@ -1327,6 +1330,16 @@
elif nametype == 'bookmarks':
oldbooks[rname] = node
+ # record a journal entry if journal is loaded
+ if util.safehasattr(repo, 'journal'):
+ for rmbookmark, newnode in bookmarks.iteritems():
+ oldnode = oldbooks.get(rmbookmark, hex(nullid))
+ if oldnode != newnode:
+ joinedremotename = joinremotename(remotepath, rmbookmark)
+ repo.journal.record(
+ journalremotebookmarktype, joinedremotename,
+ bin(oldnode), bin(newnode))
+
for branch, nodes in branches.iteritems():
for n in nodes:
rname = joinremotename(remotepath, branch)
diff --git a/tests/test-journal.t b/tests/test-journal.t
new file mode 100644
--- /dev/null
+++ b/tests/test-journal.t
@@ -0,0 +1,64 @@
+Tests for the journal extension integration with remotenames.
+
+Skip if journal is not available in mercurial
+
+ $ if ! hg help -e journal &>/dev/null; then
+ > echo 'skipped: missing feature: journal'
+ > exit 80
+ > fi
+
+ $ cat >> $HGRCPATH << EOF
+ > [extensions]
+ > journal=
+ > remotenames=`dirname $TESTDIR`/remotenames.py
+ > [remotenames]
+ > rename.default=remote
+ > EOF
+
+ $ hg init remote
+ $ cd remote
+ $ touch a
+ $ hg commit -A -m 'a commit' -q
+ $ hg book bmwillnotmove
+ $ hg book bm
+
+Test journal with remote bookmarks works on clone
+
+ $ cd ..
+ $ hg clone remote local -q
+ $ cd local
+ $ hg journal remote/bm
+ previous locations of 'remote/bm':
+ 94cf1ae9e2c8 clone remote local -q
+
+Test journal with remote bookmarks works on pull
+
+ $ cd ../remote
+ $ hg up bm -q
+ $ echo 'modified' > a
+ $ hg commit -m 'a second commit' -q
+ $ cd ../local
+ $ hg pull -q
+ $ hg journal remote/bm
+ previous locations of 'remote/bm':
+ b720e98e7160 pull -q
+ 94cf1ae9e2c8 clone remote local -q
+
+Test journal with remote bookmarks works after push
+
+ $ hg up remote/bm -q
+ $ echo 'modified locally' > a
+ $ hg commit -m 'local commit' -q
+ $ hg push --to bm -q
+ $ hg journal remote/bm
+ previous locations of 'remote/bm':
+ 869ef7e9b417 push --to bm -q
+ b720e98e7160 pull -q
+ 94cf1ae9e2c8 clone remote local -q
+
+Test second remotebookmark has not been clobbered or has moved since clone
+
+ $ hg journal remote/bmwillnotmove
+ previous locations of 'remote/bmwillnotmove':
+ 94cf1ae9e2c8 clone remote local -q
+
More information about the Mercurial-devel
mailing list