changeset 47:3b62270c1fad

writing some status output after a push, updating local bookmarks
author Scott Chacon <schacon@gmail.com>
date Wed, 29 Apr 2009 10:03:16 -0700
parents 0bfcd0c06b8e
children 1421d04f1ad2
files TODO.txt dulwich/client.py dulwich/repo.py git_handler.py
diffstat 4 files changed, 38 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/TODO.txt
+++ b/TODO.txt
@@ -9,6 +9,13 @@
 
 PUSH
 ==========
+
+Getting (and not sure why):
+  error: Ref refs/heads/master is at 093772e7fa2ee3c0d488bc44317cfe66d72f09ed  
+         but expected a89be0ca4c09782b6275a8e826c11a91b860a071
+  error: failed to lock refs/heads/master
+  (it works, but why is it doing this?)
+
 * push with branch names (w/ proper error messages)
 * update 'remote' references after push confirmation
 * push confirmation? is there extra data after the packfile upload?
--- a/dulwich/client.py
+++ b/dulwich/client.py
@@ -36,7 +36,7 @@
 from pack import (
     write_pack_data,
     )
-
+from objects import sha_to_hex
 
 def _fileno_can_read(fileno):
     return len(select.select([fileno], [], [], 0)[0]) > 0
@@ -119,6 +119,7 @@
             print 'nothing changed'
             self.proto.write_pkt_line(None)
             return
+        return_refs = copy.copy(changed_refs)
         self.proto.write_pkt_line("%s %s %s\0%s" % (changed_refs[0][0], changed_refs[0][1], changed_refs[0][2], self.capabilities()))
         want = []
         have = []
@@ -130,14 +131,23 @@
         self.proto.write_pkt_line(None)
         shas = generate_pack_contents(want, have)
             
+        # write packfile contents to a temp file
         (fd, tmppath) = tempfile.mkstemp(suffix=".pack")
         f = os.fdopen(fd, 'w')        
         (entries, sha) = write_pack_data(f, shas, len(shas))
 
+        # write that temp file to our filehandle
         f = open(tmppath, "r")
         self.proto.write_file(f)
         self.proto.write(sha)
         f.close()
+        
+        # read the final confirmation sha
+        sha = self.proto.read(20)
+        if sha:
+            print "CONFIRM: " + sha_to_hex(sha)
+            
+        return return_refs
 
     def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress):
         """Retrieve a pack from a git smart server.
@@ -207,7 +217,7 @@
         :param path: Path of the repository on the remote host
         """
         self.proto.send_cmd("git-receive-pack", path, "host=%s" % self.host)
-        super(TCPGitClient, self).send_pack(path, changed_refs, generate_pack_contents)
+        return super(TCPGitClient, self).send_pack(path, changed_refs, generate_pack_contents)
 
     def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress):
         """Fetch a pack from the remote host.
@@ -244,7 +254,7 @@
 
     def send_pack(self, path, changed_refs, generate_pack_contents):
         client = self._connect("git-receive-pack", path)
-        client.send_pack(path, changed_refs, generate_pack_contents)
+        return client.send_pack(path, changed_refs, generate_pack_contents)
 
     def fetch_pack(self, path, determine_wants, graph_walker, pack_data, 
         progress):
@@ -300,7 +310,7 @@
     def send_pack(self, path, changed_refs, generate_pack_contents):
         remote = get_ssh_vendor().connect_ssh(self.host, ["git-receive-pack '%s'" % path], port=self.port)
         client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs)
-        client.send_pack(path, changed_refs, generate_pack_contents)
+        return client.send_pack(path, changed_refs, generate_pack_contents)
 
     def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress):
         remote = get_ssh_vendor().connect_ssh(self.host, ["git-upload-pack '%s'" % path], port=self.port)
--- a/dulwich/repo.py
+++ b/dulwich/repo.py
@@ -346,7 +346,7 @@
     # takes a hash of the commit data
     # {'author': 'Scott Chacon <schacon@gmail.com> 1240868341 -0700'
     #  'committer': 'Scott Chacon <schacon@gmail.com> 1240868341 -0700',
-    #  'message': 'test commit two\n\n--HG EXTRAS--\nbranch : default\n',
+    #  'message': 'test commit two\n\n--HG--\nbranch : default\n',
     #  'tree': '36a63c12d097b487e4ed634c34d2f80870e64f68',
     #  'parents': ['ca82a6dff817ec66f44342007202690a93763949'],
     #  }
--- a/git_handler.py
+++ b/git_handler.py
@@ -286,8 +286,13 @@
         changed = self.get_changed_refs
         genpack = self.generate_pack_contents
         try:
-            client.send_pack(path, changed, genpack)
-            # TODO : self.git.set_remote_refs(refs, remote_name)
+            changed_refs = client.send_pack(path, changed, genpack)
+            new_refs = {}
+            for old, new, ref in changed_refs:
+                self.ui.status("    "+ remote_name + "::" + ref + " : GIT:" + old[0:8] + " => GIT:" + new[0:8] + "\n")
+                new_refs[ref] = new
+            self.git.set_remote_refs(new_refs, remote_name)
+            self.update_hg_bookmarks(remote_name)
         except:
             raise
 
@@ -404,18 +409,20 @@
             commit = convert_list[csha]
             self.import_git_commit(commit)
 
-        # update Hg bookmarks
-        bms = {}
-        for head, sha in self.git.remote_refs(remote_name).iteritems():
-            hgsha = hex_to_sha(self.map_hg_get(sha))
-            if not head == 'HEAD':
-                bms[remote_name + '/' + head] = hgsha
+        self.update_hg_bookmarks(remote_name)
+
+    def update_hg_bookmarks(self, remote_name):
         try:
+            bms = bookmarks.parse(self.repo)
+            for head, sha in self.git.remote_refs(remote_name).iteritems():
+                hgsha = hex_to_sha(self.map_hg_get(sha))
+                if not head == 'HEAD':
+                    bms[remote_name + '/' + head] = hgsha
             bookmarks.write(self.repo, bms)
         except AttributeError:
             self.repo.ui.warn('creating bookmarks failed, do you have'
                               ' bookmarks enabled?\n')
-
+        
     def import_git_commit(self, commit):
         print "importing: " + commit.id
         # TODO : look for HG metadata in the message and use it
@@ -457,12 +464,6 @@
         gitsha = commit.id
         self.map_set(gitsha, p2)
 
-    def getfilectx(self, source, repo, memctx, f):
-        v = files[f]
-        data = source.getfile(f, v)
-        e = source.getmode(f, v)
-        return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
-
     def check_bookmarks(self):
         if self.ui.config('extensions', 'hgext.bookmarks') is not None:
             print "YOU NEED TO SETUP BOOKMARKS"