[PATCH 1 of 4] pull: work as usual bare "hg update" for URL#BRANCH

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Feb 17 19:49:25 UTC 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1455738388 -32400
#      Thu Feb 18 04:46:28 2016 +0900
# Node ID 4da9702b2eef28a1c6097f5dbce322bec8925fcd
# Parent  95bf01b8754016200a99fd3538e78030b2028c60
pull: work as usual bare "hg update" for URL#BRANCH

Ordinarily, "hg pull -u" works as same as "hg pull" + bare "hg update"
(without any explicit revision), for example:

  - advance current active bookmark, if the destination of the update
    is valid for 'bookmarks.validdest()'

  - update not to branch tip but to active bookmark, if the latter is
    already updated at pulling changes

But before this patch, "hg pull -u" for "URL#BRANCH" doesn't work as
expected.

  - current active bookmark is never advanced

  - update to branch tip always

This seems not reasonable for a user, who works on the branch "BRANCH"
in the repo cloned by "URL#BRANCH".

But, on the other hand, if "hg pull" is executed with explicit
--branch/--rev, or "URL#ANOTHER-BRANCH" source, this behavior seems
reasonable, because user would want to update to specified revision
(or branch tip).

This patch treats updating at "hg pull -u" as bare "hg update", if:

  - no --branch/--rev is specified, and
  - current branch name is equal to "fragment" of "URL#fragment"

In this case, 'checkout = None' makes postincoming() use
destutil.destupdate() to calculate the destination of the update and
the bookmark to be advanced, as same as usual bare "hg update".

This patch doesn't examine whether explicit --bookmark is specified or
not, because it isn't used to determine which revision should be
'checkout'.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5656,7 +5656,16 @@ def pull(ui, repo, source="default", **o
                                  bookmarks=opts.get('bookmark', ()),
                                  opargs=pullopargs).cgresult
         if checkout:
-            checkout = str(repo.changelog.rev(checkout))
+            fragment = branches[0]
+            # treat "hg pull -u URL#fragment" as same as "hg pull" +
+            # usual bare "hg update", if:
+            #   - no --branch/--rev, and
+            #   - branch name is equal to "fragment"
+            if (not opts.get('branch') and not opts.get('rev') and
+                repo.dirstate.branch() == fragment):
+                checkout = None
+            else:
+                checkout = str(repo.changelog.rev(checkout))
         repo._subtoppath = source
         try:
             ret = postincoming(ui, repo, modheads, opts.get('update'), checkout)
diff --git a/tests/test-pull-update.t b/tests/test-pull-update.t
--- a/tests/test-pull-update.t
+++ b/tests/test-pull-update.t
@@ -61,4 +61,134 @@ Should work:
   added 1 changesets with 1 changes to 1 files (-1 heads)
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
+Similarity between "hg update" and "hg pull -u" in handling bookmark
+====================================================================
+
+  $ hg branch -q bar
+  $ hg commit -m "bar #1"
+  $ hg --cwd .. clone -q t#bar clone-bar
+  $ echo bar2 >> foo
+  $ hg commit -m "bar #2"
+
+  $ cd ../clone-bar
+
+Test that "hg pull -u URL#fragment" is as same as "hg pull
+URL#fragment" + bare "hg update", if:
+- no explicit --branch/--rev and
+- current branch name is equal to "fragment" of "URL#fragment"
+
+(1) advancing active bookmark
+
+  $ hg branch
+  bar
+  $ hg parents -q
+  4:20a3d5b6ab59
+  $ hg bookmark active-before-pull
+  $ hg bookmarks
+   * active-before-pull        4:20a3d5b6ab59
+
+  $ hg pull -u
+  pulling from $TESTTMP/t (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updating bookmark active-before-pull
+
+  $ hg branch
+  bar
+  $ hg parents -q
+  5:9ed4148f9a91
+  $ hg bookmarks
+   * active-before-pull        5:9ed4148f9a91
+
+(discard pulled changes: strip is needed in this case, because
+rollback just rewinds bookmark, which is advanced at previous pulling)
+
+  $ hg update -q 20a3d5b6ab59
+  $ hg rollback -q
+  $ hg --config extensions.strip= strip -q 9ed4148f9a91
+
+(2) updating not to branch tip but to (already updated) active bookmark
+
+  $ echo bar3 >> ../t/foo
+  $ hg -R ../t commit -m "bar #3"
+  $ hg -R ../t bookmark -r 9ed4148f9a91 active-before-pull
+
+  $ hg bookmark -f active-before-pull
+  $ hg bookmarks
+   * active-before-pull        4:20a3d5b6ab59
+
+  $ hg pull -u
+  pulling from $TESTTMP/t (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 1 files
+  updating bookmark active-before-pull
+  updating to active bookmark active-before-pull
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg parents -q
+  5:9ed4148f9a91
+  $ hg bookmarks
+   * active-before-pull        5:9ed4148f9a91
+
+Test updating for multiple heads:
+
+  $ hg -R ../t update -q 20a3d5b6ab59
+  $ echo bar4 >> ../t/foo
+  $ hg -R ../t commit -m "bar #4"
+  created new head
+
+  $ hg -R ../t log -G -b bar -T "{node|short}"
+  @  424b5eb9b087
+  |
+  | o  0c90a742bd4f
+  | |
+  | o  9ed4148f9a91
+  |/
+  o  20a3d5b6ab59
+  |
+
+(1) update linearly and show "other heads" status like as bare "hg
+update", if pulling even from "URL#BRANCH", but no explicit --branch/--rev
+
+  $ hg update -C -q 0c90a742bd4f
+
+  $ hg pull -u
+  pulling from $TESTTMP/t (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 other heads for branch "bar"
+
+  $ hg parents -q
+  6:0c90a742bd4f
+
+(discard pulled changes)
+
+  $ hg update -C -q 0c90a742bd4f
+  $ hg rollback -q
+
+(2) update to "branch tip" on another topological branch, otherwise
+
+  $ hg pull -u -r bar
+  pulling from $TESTTMP/t (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg parents -q
+  7:424b5eb9b087
+
   $ cd ..


More information about the Mercurial-devel mailing list