Commits

David Carr  committed 71bd006

checkpoint work towards branch deletion

  • Participants
  • Parent commits aa9b012

Comments (0)

Files changed (1)

File bookmark-delete.diff

 # HG changeset patch
-# Parent ee4730c8fa9091f943f45d5219048d97c58a9c94
+# Parent 878ae1d1bd73f5e079f6990b4a93e9a9f5405fb8
 WIP: bookmark delete
 
-diff -r ee4730c8fa90 -r 65e74f7d7e77 hggit/git_handler.py
---- a/hggit/git_handler.py	Thu Sep 13 23:27:15 2012 -0400
-+++ b/hggit/git_handler.py	Fri Sep 14 18:16:06 2012 -0400
-@@ -879,8 +879,10 @@
+diff -r 878ae1d1bd73 hggit/git_handler.py
+--- a/hggit/git_handler.py	Fri Sep 14 19:10:18 2012 -0400
++++ b/hggit/git_handler.py	Sat Sep 15 14:27:11 2012 -0400
+@@ -244,6 +244,21 @@
+         except (HangupException, GitProtocolError), e:
+             raise hgutil.Abort(_("git remote error: ") + str(e))
+ 
++    def delete_ref(self, remote, key):
++        client, path = self.get_transport_and_path(remote)
++        def changed(refs):
++            new_refs = refs.copy()
++            new_refs['refs/heads/' + key] = "00" * 20
++            return new_refs
++        try:
++            client.send_pack(path, changed, lambda have, want: [])
++        except (HangupException, GitProtocolError), e:
++            raise hgutil.Abort(_("git remote error: ") + str(e))
++        refs = self.git.get_refs()
++        remote_name = self.remote_name(remote)
++        del refs['refs/heads/' + key]
++        self.update_remote_branches(remote_name, refs)
++
+     def push(self, remote, revs, force):
+         self.export_commits()
+         old_refs, new_refs = self.upload_pack(remote, revs, force)
+@@ -879,8 +894,9 @@
              tags = [t for t in prep(labels(ctx)) if t in self.tags]
  
              if not (heads or tags):
 -                raise hgutil.Abort("revision %s cannot be pushed since"
 -                                   " it doesn't have a ref" % ctx)
-+                # TODO DC tweak this?
 +                if rev != nullid:
 +                    raise hgutil.Abort("revision %s cannot be pushed since"
 +                                       " it doesn't have a ref" % ctx)
  
              # Check if the tags the server is advertising are annotated tags,
              # by attempting to retrieve it from the our git repo, and building a
-diff -r ee4730c8fa90 -r 65e74f7d7e77 hggit/gitrepo.py
---- a/hggit/gitrepo.py	Thu Sep 13 23:27:15 2012 -0400
-+++ b/hggit/gitrepo.py	Fri Sep 14 18:16:06 2012 -0400
-@@ -38,10 +38,22 @@
+diff -r 878ae1d1bd73 hggit/gitrepo.py
+--- a/hggit/gitrepo.py	Fri Sep 14 19:10:18 2012 -0400
++++ b/hggit/gitrepo.py	Sat Sep 15 14:27:11 2012 -0400
+@@ -1,3 +1,4 @@
++import os
+ from mercurial import util
+ try:
+     from mercurial.error import RepoError
+@@ -38,9 +39,28 @@
          return []
  
      def listkeys(self, namespace):
--        return {}
-+        if namespace == 'bookmarks':
-+            #return instance.
-+            print 'listkeys ' + namespace + ' called'
-+            # TODO DC implement for branch deletion
-+            #return {}
-+            return {'beta': 'test'}
-+        else:
-+            return {}
++        if namespace == 'bookmarks' and self.git_handler:
++            git = self.git_handler
++            repo = git.repo
++            remote_name = git.remote_name(self.path)
++            tagfile = repo.join(os.path.join('git-remote-refs'))
++            if os.path.exists(tagfile):
++                tf = open(tagfile, 'rb')
++                tagdata = tf.read().split('\n')
++                td = [line.split(' ', 1) for line in tagdata if line]
++                refs = dict([(name, sha) for sha, name in td])
++                bookmarks = {}
++                for ref, sha in refs.iteritems():
++                    if ref.startswith(remote_name + '/'):
++                        bookmarks[ref[len(remote_name)+1:]] = sha
++                return bookmarks
+         return {}
  
      def pushkey(self, namespace, key, old, new):
--        return False
-+        if namespace == 'bookmarks':
-+            # TODO DC implement for branch deletion
-+            print 'pushkey ' + namespace + ' ' + key + ' called'
-+            return True
-+        else:
-+            return False
++        if namespace == 'bookmarks' and self.git_handler:
++            if new == '':
++                self.git_handler.delete_ref(self.path, key)
++                return True
+         return False
  
      # used by incoming in hg <= 1.6
-     def branches(self, nodes):
-diff -r ee4730c8fa90 -r 65e74f7d7e77 tests/test-push.t
---- a/tests/test-push.t	Thu Sep 13 23:27:15 2012 -0400
-+++ b/tests/test-push.t	Fri Sep 14 18:16:06 2012 -0400
-@@ -57,6 +57,7 @@
-   $ hgcommit -m 'add gamma'
- 
-   $ hg book -r 1 beta
-+TODO DC: this looks like this is sharing a bookmark without -B, which is inconsistent
-   $ hg push -r beta
-   pushing to $TESTTMP/gitrepo
-   exporting hg objects to git
-@@ -151,5 +152,20 @@
+diff -r 878ae1d1bd73 hggit/hgrepo.py
+--- a/hggit/hgrepo.py	Fri Sep 14 19:10:18 2012 -0400
++++ b/hggit/hgrepo.py	Sat Sep 15 14:27:11 2012 -0400
+@@ -11,6 +11,7 @@
+         def pull(self, remote, heads=None, force=False):
+             if isinstance(remote, gitrepo):
+                 git = GitHandler(self, self.ui)
++                remote.git_handler = git
+                 return git.fetch(remote.path, heads)
+             else: #pragma: no cover
+                 return super(hgrepo, self).pull(remote, heads, force)
+@@ -19,6 +20,7 @@
+         def push(self, remote, force=False, revs=None, newbranch=None):
+             if isinstance(remote, gitrepo):
+                 git = GitHandler(self, self.ui)
++                remote.git_handler = git
+                 return git.push(remote.path, revs, force)
+             else: #pragma: no cover
+                 # newbranch was added in 1.6
+@@ -31,6 +33,7 @@
+         def findoutgoing(self, remote, base=None, heads=None, force=False):
+             if isinstance(remote, gitrepo):
+                 git = GitHandler(self, self.ui)
++                remote.git_handler = git
+                 base, heads = git.get_refs(remote.path)
+                 out, h = super(hgrepo, self).findoutgoing(remote, base, heads, force)
+                 return out
+diff -r 878ae1d1bd73 tests/test-push.t
+--- a/tests/test-push.t	Fri Sep 14 19:10:18 2012 -0400
++++ b/tests/test-push.t	Sat Sep 15 14:27:11 2012 -0400
+@@ -151,5 +151,30 @@
    creating and sending data
    no changes found
    [1]
  
 +delete a remote branch
 +  $ cd gitrepo
-+  $ git log --all
-+  $ git branch --list
++  $ git branch --list | grep beta
++    beta
    $ cd ..
 +  $ cd hgrepo
-+  $ hg log
++  $ hg log --rev 1 | grep -e bookmark -e tag
++  bookmark:    beta
++  tag:         default/beta
 +  $ hg bookmark --delete beta
 +  $ hg push -B beta
-+  $ hg log
++  pushing to $TESTTMP/gitrepo
++  creating and sending data
++  no changes found
++  deleting remote bookmark beta
++  [1]
++  $ ! (hg log --rev 1 | grep -e bookmark -e tag)
 +  $ cd ..
 +  $ cd gitrepo
-+  $ git log --all
-+  $ git branch --list
++  $ ! (git branch --list | grep beta)
 +  $ cd ..
++  $ cd hgrepo
++  $ hg pull > /dev/null
++  $ ! (hg log --rev 1 | grep -e bookmark -e tag)
++  $ cd ..