[PATCH 2 of 2] bookmarks: show details of difference between local and remote bookmarks
David M. Carr
david at carrclan.us
Sun Sep 23 12:28:48 CDT 2012
On Sat, Sep 22, 2012 at 1:56 AM, FUJIWARA Katsunori
<foozy at lares.dti.ne.jp> wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1348293230 -32400
> # Node ID fb900c89f96b209486068ef2cdb4b9af43db1de6
> # Parent 750be2c38db4e86c3f09d0cae83e9af9d49795e7
> bookmarks: show details of difference between local and remote bookmarks
>
> Before this patch, "hg incoming"/"hg outgoing" with -B show only
> bookmarks newly added on the source repository.
>
> So, users can't know whether "hg push"/"hg pull" cause divergence or
> overwriting of specific bookmark or not, before execution of them.
>
> This patch shows not only newly added bookmarks, but also details of
> difference between local and remote bookmarks.
>
> For local bookmarks which are different from ones on remote, details
> of them are decided as below: each of "b at local" and "b at remote" are
> assumed to mean revisions referred by bookmarks on each sides.
>
> - if "b at remote" is contained in the local:
> - if "b at local" and "b at remote" are diverged, show as "(diverged)"
> - if "b at local" < "b at remote", show as "(advanced on the remote)"
> - otherwise("b at remoet" < "b at local"), show as "(advanced on the local)"
> - otherwise:
> - show as "(different from the remote)", because "b at local" is
> different from "b at remote", but divergence of them can't be
> examined with low cost
>
> Examination divergence between revisions by 'changectx.descendant()'
> costs "O(N)" for the number of revisions between ones referred by
> local and remote bookmarks at most.
>
> diff -r 750be2c38db4 -r fb900c89f96b mercurial/bookmarks.py
> --- a/mercurial/bookmarks.py Sat Sep 22 14:53:50 2012 +0900
> +++ b/mercurial/bookmarks.py Sat Sep 22 14:53:50 2012 +0900
> @@ -237,16 +237,55 @@
> if changed:
> write(repo)
>
> -def diff(ui, dst, src):
> +def diff(ui, dst, src, local):
> ui.status(_("searching for changed bookmarks\n"))
>
> smarks = src.listkeys('bookmarks')
> dmarks = dst.listkeys('bookmarks')
>
> - diff = sorted(set(smarks) - set(dmarks))
> - for k in diff:
> + smarkset = set(smarks)
> + dmarkset = set(dmarks)
> + diff = smarkset - dmarkset
> + for k in smarkset & dmarkset:
> + if smarks[k] != dmarks[k]:
> + diff.add(k)
> + if dst.local() == local:
> + # incoming
> + advmsgs = [
> + _("(advanced on the local)"), # b at src < b at dst(local)
> + _("(advanced on the remote)"), # b at dst(local) < b at src
> + ]
> + addmsg = _("(added on the remote)")
> + else:
> + # outgoing
> + advmsgs = [
> + _("(advanced on the remote)"), # b at src(local) < b at dst
> + _("(advanced on the local)"), # b at dst < b at src(local)
> + ]
> + addmsg = _("(added on the local)")
> + for k in sorted(diff):
> mark = ui.debugflag and smarks[k] or smarks[k][:12]
> - ui.write(" %-25s %s\n" % (k, mark))
> + if k in dmarks:
> + scid = smarks[k]
> + dcid = dmarks[k]
> + if scid in local and dcid in local:
> + sctx = local[scid]
> + dctx = local[dcid]
> + if sctx.rev() < dctx.rev():
> + if sctx.descendant(dctx):
> + msg = advmsgs[0]
> + else:
> + msg = _("(diverged)")
> + else:
> + if dctx.descendant(sctx):
> + msg = advmsgs[1]
> + else:
> + msg = _("(diverged)")
> + else:
> + msg = _("(different from the remote)")
> + else:
> + msg = addmsg
> + ui.write(" %-25s %s %s\n" % (k, mark, msg))
>
> if len(diff) <= 0:
> ui.status(_("no changed bookmarks found\n"))
> diff -r 750be2c38db4 -r fb900c89f96b mercurial/commands.py
> --- a/mercurial/commands.py Sat Sep 22 14:53:50 2012 +0900
> +++ b/mercurial/commands.py Sat Sep 22 14:53:50 2012 +0900
> @@ -3894,7 +3894,7 @@
> ui.warn(_("remote doesn't support bookmarks\n"))
> return 0
> ui.status(_('comparing with %s\n') % util.hidepassword(source))
> - return bookmarks.diff(ui, repo, other)
> + return bookmarks.diff(ui, repo, other, repo)
>
> repo._subtoppath = ui.expandpath(source)
> try:
> @@ -4358,7 +4358,7 @@
> ui.warn(_("remote doesn't support bookmarks\n"))
> return 0
> ui.status(_('comparing with %s\n') % util.hidepassword(dest))
> - return bookmarks.diff(ui, other, repo)
> + return bookmarks.diff(ui, other, repo, repo)
>
> repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default')
> try:
> diff -r 750be2c38db4 -r fb900c89f96b tests/test-bookmarks-pushpull.t
> --- a/tests/test-bookmarks-pushpull.t Sat Sep 22 14:53:50 2012 +0900
> +++ b/tests/test-bookmarks-pushpull.t Sat Sep 22 14:53:50 2012 +0900
> @@ -268,11 +268,19 @@
> Z 0d2164f0ce0d8f1d6f94351eba04b794909be66c
> foo 0000000000000000000000000000000000000000
> X 9b140be1080824d768c5a4691a564088eede71f9
> + $ hg log -G --template '{node|short} ({bookmarks})'
> + o 4efff6d98829 (Y)
> + |
> + | o 9b140be10808 ()
> + |/
> + | @ 0d2164f0ce0d (X Z)
> + |/
> + o 4e3505fd9583 ()
> +
> $ hg out -B http://localhost:$HGPORT/
> comparing with http://localhost:$HGPORT/
> searching for changed bookmarks
> - no changed bookmarks found
> - [1]
> + X 0d2164f0ce0d (diverged)
> $ hg push -B Z http://localhost:$HGPORT/
> pushing to http://localhost:$HGPORT/
> searching for changes
> @@ -283,9 +291,10 @@
> $ hg in -B http://localhost:$HGPORT/
> comparing with http://localhost:$HGPORT/
> searching for changed bookmarks
> - Z 0d2164f0ce0d
> - foo 000000000000
> - foobar 9b140be10808
> + X 9b140be10808 (diverged)
> + Z 0d2164f0ce0d (added on the remote)
> + foo 000000000000 (added on the remote)
> + foobar 9b140be10808 (added on the remote)
> $ hg pull -B Z http://localhost:$HGPORT/
> pulling from http://localhost:$HGPORT/
> no changes found
> @@ -344,3 +353,101 @@
> exporting bookmark add-foo
>
> $ cd ..
> +
> +Test to show result of bookmarks comparision with kind of difference:
> +this also tests to show not only added bookmarks but also changed
> +bookmarks.
> +
> + $ mkdir bookmarkdiff
> + $ cd bookmarkdiff
> +
> + $ hg init source
> + $ hg -R source debugbuilddag '+2*2*3*4'
> + $ hg -R source log -G --template '{rev}:{node|short}'
> + o 4:e7bd5218ca15
> + |
> + | o 3:6100d3090acf
> + |/
> + | o 2:fa942426a6fd
> + |/
> + | o 1:66f7d451a68b
> + |/
> + o 0:1ea73414a91b
> +
> + $ hg -R source bookmarks -r 0 SAME
> + $ hg -R source bookmarks -r 0 ADV_ON_REPO2
> + $ hg -R source bookmarks -r 1 DIVERGED
> + $ hg -R source bookmarks -r 0 DIFF_ADV_ON_REPO1
> + $ hg -R source bookmarks -r 0 DIFF_ADV_ON_REPO2
> +
> + $ hg clone -U source repo1
> + $ hg -R repo1 bookmarks -f -r 1 ADD_ON_REPO1
> + $ hg -R repo1 bookmarks -f -r 3 DIFF_ADV_ON_REPO1
> + $ hg -R repo1 bookmarks -f -r 3 DIFF_DIVERGED
> + $ hg -R repo1 -q --config extensions.mq= strip 4
> + $ hg -R repo1 log -G --template '{node|short} ({bookmarks})'
> + o 6100d3090acf (DIFF_ADV_ON_REPO1 DIFF_DIVERGED)
> + |
> + | o fa942426a6fd ()
> + |/
> + | o 66f7d451a68b (ADD_ON_REPO1 DIVERGED)
> + |/
> + o 1ea73414a91b (ADV_ON_REPO2 DIFF_ADV_ON_REPO2 SAME)
> +
> +
> + $ hg clone -U source repo2
> + $ hg -R repo2 bookmarks -f -r 1 ADD_ON_REPO2
> + $ hg -R repo2 bookmarks -f -r 1 ADV_ON_REPO2
> + $ hg -R repo2 bookmarks -f -r 2 DIVERGED
> + $ hg -R repo2 bookmarks -f -r 4 DIFF_ADV_ON_REPO2
> + $ hg -R repo2 bookmarks -f -r 4 DIFF_DIVERGED
> + $ hg -R repo2 -q --config extensions.mq= strip 3
> + $ hg -R repo2 log -G --template '{node|short} ({bookmarks})'
> + o e7bd5218ca15 (DIFF_ADV_ON_REPO2 DIFF_DIVERGED)
> + |
> + | o fa942426a6fd (DIVERGED)
> + |/
> + | o 66f7d451a68b (ADD_ON_REPO2 ADV_ON_REPO2)
> + |/
> + o 1ea73414a91b (DIFF_ADV_ON_REPO1 SAME)
> +
> +
> + $ hg -R repo1 incoming -B repo2
> + comparing with repo2
> + searching for changed bookmarks
> + ADD_ON_REPO2 66f7d451a68b (added on the remote)
> + ADV_ON_REPO2 66f7d451a68b (advanced on the remote)
> + DIFF_ADV_ON_REPO1 1ea73414a91b (advanced on the local)
> + DIFF_ADV_ON_REPO2 e7bd5218ca15 (different from the remote)
> + DIFF_DIVERGED e7bd5218ca15 (different from the remote)
> + DIVERGED fa942426a6fd (diverged)
> + $ hg -R repo1 outgoing -B repo2
> + comparing with repo2
> + searching for changed bookmarks
> + ADD_ON_REPO1 66f7d451a68b (added on the local)
> + ADV_ON_REPO2 1ea73414a91b (advanced on the remote)
> + DIFF_ADV_ON_REPO1 6100d3090acf (advanced on the local)
> + DIFF_ADV_ON_REPO2 1ea73414a91b (different from the remote)
> + DIFF_DIVERGED 6100d3090acf (different from the remote)
> + DIVERGED 66f7d451a68b (diverged)
> +
> + $ hg -R repo2 incoming -B repo1
> + comparing with repo1
> + searching for changed bookmarks
> + ADD_ON_REPO1 66f7d451a68b (added on the remote)
> + ADV_ON_REPO2 1ea73414a91b (advanced on the local)
> + DIFF_ADV_ON_REPO1 6100d3090acf (different from the remote)
> + DIFF_ADV_ON_REPO2 1ea73414a91b (advanced on the local)
> + DIFF_DIVERGED 6100d3090acf (different from the remote)
> + DIVERGED 66f7d451a68b (diverged)
> + $ hg -R repo2 outgoing -B repo1
> + comparing with repo1
> + searching for changed bookmarks
> + ADD_ON_REPO2 66f7d451a68b (added on the local)
> + ADV_ON_REPO2 66f7d451a68b (advanced on the local)
> + DIFF_ADV_ON_REPO1 1ea73414a91b (different from the remote)
> + DIFF_ADV_ON_REPO2 e7bd5218ca15 (advanced on the local)
> + DIFF_DIVERGED e7bd5218ca15 (different from the remote)
> + DIVERGED fa942426a6fd (diverged)
> +
> + $ cd ..
> diff -r 750be2c38db4 -r fb900c89f96b tests/test-ssh.t
> --- a/tests/test-ssh.t Sat Sep 22 14:53:50 2012 +0900
> +++ b/tests/test-ssh.t Sat Sep 22 14:53:50 2012 +0900
> @@ -171,7 +171,7 @@
> $ hg out -B
> comparing with ssh://user@dummy/remote
> searching for changed bookmarks
> - foo 1160648e36ce
> + foo 1160648e36ce (added on the local)
> $ hg push -B foo
> pushing to ssh://user@dummy/remote
> searching for changes
> @@ -191,7 +191,7 @@
> $ hg in -B
> comparing with ssh://user@dummy/remote
> searching for changed bookmarks
> - foo a28a9d1a809c
> + foo a28a9d1a809c (added on the remote)
> $ hg book -f -r 0 foo
> $ hg pull -B foo
> pulling from ssh://user@dummy/remote
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
I hadn't realized before this that "hg outgoing -B" currently doesn't
give any indication of existing remote bookmarks that will be updated.
+1 for allowing "hg outgoing -B" to better tell users what will
happen when they do an "hg push".
--
David M. Carr
david at carrclan.us
More information about the Mercurial-devel
mailing list