changeset 604:6da65b534370

merge
author Augie Fackler <raf@durin42.com>
date Wed, 28 Aug 2013 13:49:01 -0400
parents f1bac7f37a05 (current diff) ca86479dd2d9 (diff)
children bd5467169d3c
files hggit/git_handler.py
diffstat 3 files changed, 145 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Aug 28 13:41:22 2013 -0400
+++ b/.hgignore	Wed Aug 28 13:49:01 2013 -0400
@@ -4,3 +4,5 @@
 build
 dist
 *.egg-info
+*.orig
+
--- a/hggit/git_handler.py	Wed Aug 28 13:41:22 2013 -0400
+++ b/hggit/git_handler.py	Wed Aug 28 13:49:01 2013 -0400
@@ -1115,6 +1115,7 @@
             heads = dict([(ref[11:],refs[ref]) for ref in refs
                           if ref.startswith('refs/heads/')])
 
+            suffix = self.branch_bookmark_suffix or ''
             for head, sha in heads.iteritems():
                 # refs contains all the refs in the server, not just
                 # the ones we are pulling
@@ -1123,28 +1124,13 @@
                 hgsha = bin(self.map_hg_get(sha))
                 if not head in bms:
                     # new branch
-                    bms[head] = hgsha
+                    bms[head + suffix] = hgsha
                 else:
                     bm = self.repo[bms[head]]
                     if bm.ancestor(self.repo[hgsha]) == bm:
                         # fast forward
-                        bms[head] = hgsha
+                        bms[head + suffix] = hgsha
 
-            # if there's a branch bookmark suffix,
-            # then add it on to all bookmark names
-            # that would otherwise conflict with a branch
-            # name
-            if self.branch_bookmark_suffix:
-                real_branch_names = self.repo.branchmap()
-                bms = dict(
-                    (
-                        bm_name + self.branch_bookmark_suffix
-                            if bm_name in real_branch_names
-                        else bm_name,
-                        bms[bm_name]
-                    )
-                    for bm_name in bms
-                )
             if heads:
                 if oldbm:
                     bookmarks.write(self.repo, bms)
@@ -1365,7 +1351,7 @@
             res = git_match.groupdict()
             transport = client.SSHGitClient if 'ssh' in res['scheme'] else client.TCPGitClient
             host, port, sepr, path = res['host'], res['port'], res['sepr'], res['path']
-            if sepr == '/':
+            if sepr == '/' and not path.startswith('~'):
                 path = '/' + path
             # strip trailing slash for heroku-style URLs
             # ssh+git://git@heroku.com:project.git/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branch-bookmark-suffix.t	Wed Aug 28 13:49:01 2013 -0400
@@ -0,0 +1,139 @@
+bail if the user does not have dulwich
+  $ python -c 'import dulwich, dulwich.repo' || exit 80
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
+  $ echo 'hgext.graphlog =' >> $HGRCPATH
+  $ echo "[git]" >> $HGRCPATH
+  $ echo "branch_bookmark_suffix=_bookmark" >> $HGRCPATH
+
+  $ GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
+  $ GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
+  $ GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
+  $ GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
+  $ GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
+  $ GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
+
+  $ count=10
+  $ commit()
+  > {
+  >     GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
+  >     GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
+  >     git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
+  >     count=`expr $count + 1`
+  > }
+  $ hgcommit()
+  > {
+  >     HGDATE="2007-01-01 00:00:$count +0000"
+  >     hg commit -d "$HGDATE" "$@" >/dev/null 2>/dev/null || echo "hg commit error"
+  >     count=`expr $count + 1`
+  > }
+
+  $ git config --global push.default matching
+  $ git init --bare gitrepo1
+  Initialized empty Git repository in $TESTTMP/gitrepo1/
+
+  $ hg init hgrepo
+  $ cd hgrepo
+  $ hg branch -q branch1
+  $ hg bookmark branch1_bookmark
+  $ echo f1 > f1
+  $ hg add f1
+  $ hgcommit -m "add f1"
+  $ hg branch -q branch2
+  $ hg bookmark branch2_bookmark
+  $ echo f2 > f2
+  $ hg add f2
+  $ hgcommit -m "add f2"
+  $ hg log --graph
+  @  changeset:   1:600de9b6d498
+  |  branch:      branch2
+  |  bookmark:    branch2_bookmark
+  |  tag:         tip
+  |  user:        test
+  |  date:        Mon Jan 01 00:00:11 2007 +0000
+  |  summary:     add f2
+  |
+  o  changeset:   0:40a840c1f8ae
+     branch:      branch1
+     bookmark:    branch1_bookmark
+     user:        test
+     date:        Mon Jan 01 00:00:10 2007 +0000
+     summary:     add f1
+  
+
+
+  $ hg push ../gitrepo1
+  pushing to ../gitrepo1
+  searching for changes
+  adding objects
+  added 2 commits with 2 trees and 2 blobs
+
+  $ cd ..
+
+  $ cd gitrepo1
+  $ git symbolic-ref HEAD refs/heads/branch1
+  $ git branch
+  * branch1
+    branch2
+  $ cd ..
+
+  $ git clone gitrepo1 gitrepo2
+  Cloning into 'gitrepo2'...
+  done.
+  $ cd gitrepo2
+  $ git checkout branch1
+  Already on 'branch1'
+  $ echo g1 >> f1
+  $ git add f1
+  $ commit -m "append f1"
+  $ git checkout branch2
+  Switched to a new branch 'branch2'
+  Branch branch2 set up to track remote branch branch2 from origin.
+  $ echo g2 >> f2
+  $ git add f2
+  $ commit -m "append f2"
+  $ git push origin
+  To $TESTTMP/gitrepo1
+     bbfe79a..d8aef79  branch1 -> branch1
+     288e92b..f8f8de5  branch2 -> branch2
+  $ cd ..
+
+  $ cd hgrepo
+  $ hg pull ../gitrepo1
+  pulling from ../gitrepo1
+  importing git objects into hg
+  (run 'hg heads' to see heads)
+  $ hg log --graph
+  o  changeset:   3:0a696ec0f478
+  |  bookmark:    branch2_bookmark
+  |  tag:         default/branch2
+  |  tag:         tip
+  |  parent:      1:600de9b6d498
+  |  user:        test <test@example.org>
+  |  date:        Mon Jan 01 00:00:13 2007 +0000
+  |  summary:     append f2
+  |
+  | o  changeset:   2:49db35e15e81
+  | |  bookmark:    branch1_bookmark
+  | |  tag:         default/branch1
+  | |  parent:      0:40a840c1f8ae
+  | |  user:        test <test@example.org>
+  | |  date:        Mon Jan 01 00:00:12 2007 +0000
+  | |  summary:     append f1
+  | |
+  @ |  changeset:   1:600de9b6d498
+  |/   branch:      branch2
+  |    user:        test
+  |    date:        Mon Jan 01 00:00:11 2007 +0000
+  |    summary:     add f2
+  |
+  o  changeset:   0:40a840c1f8ae
+     branch:      branch1
+     user:        test
+     date:        Mon Jan 01 00:00:10 2007 +0000
+     summary:     add f1
+  
+
+
+  $ cd ..