Mercurial > hg-git
changeset 4:9150a8f9d1f2
fetch will now set refs properly, including namespaced ones
author | Scott Chacon <schacon@gmail.com> |
---|---|
date | Thu, 23 Apr 2009 12:11:23 -0700 |
parents | 9bd66568bc41 |
children | d6c443a91b18 |
files | __init__.py dulwich/client.py dulwich/repo.py |
diffstat | 3 files changed, 19 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/__init__.py Thu Apr 23 10:40:38 2009 -0700 +++ b/__init__.py Thu Apr 23 12:11:23 2009 -0700 @@ -74,12 +74,10 @@ r = Repo(git_dir) graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents) f, commit = r.object_store.add_pack() - try: - client.fetch_pack(path, r.object_store.determine_wants_all, graphwalker, f.write, sys.stdout.write) - f.close() - commit() - except: - f.close() + refs = client.fetch_pack(path, r.object_store.determine_wants_all, graphwalker, f.write, sys.stdout.write) + f.close() + commit() + r.set_refs(refs) def get_transport_and_path(uri): from dulwich.client import TCPGitClient, SSHGitClient, SubprocessGitClient
--- a/dulwich/client.py Thu Apr 23 10:40:38 2009 -0700 +++ b/dulwich/client.py Thu Apr 23 12:11:23 2009 -0700 @@ -25,6 +25,7 @@ import select import socket import subprocess +import copy from protocol import ( Protocol, @@ -137,6 +138,7 @@ :param progress: Callback for progress reports (strings) """ (refs, server_capabilities) = self.read_refs() + refsreturn = copy.deepcopy(refs) wants = determine_wants(refs) if not wants: self.proto.write_pkt_line(None) @@ -173,6 +175,7 @@ progress(pkt) else: raise AssertionError("Invalid sideband channel %d" % channel) + return refsreturn class TCPGitClient(GitClient): @@ -207,7 +210,7 @@ :param progress: Callback for writing progress """ self.proto.send_cmd("git-upload-pack", path, "host=%s" % self.host) - super(TCPGitClient, self).fetch_pack(path, determine_wants, graph_walker, pack_data, progress) + return super(TCPGitClient, self).fetch_pack(path, determine_wants, graph_walker, pack_data, progress) class SubprocessGitClient(GitClient): @@ -236,7 +239,7 @@ def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress): client = self._connect("git-upload-pack", path) - client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress) + return client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress) class SSHSubprocess(object): @@ -292,5 +295,5 @@ 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) client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs) - client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress) + return client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress)
--- a/dulwich/repo.py Thu Apr 23 10:40:38 2009 -0700 +++ b/dulwich/repo.py Thu Apr 23 12:11:23 2009 -0700 @@ -231,8 +231,17 @@ finally: f.close() + def set_refs(self, refs): + keys = refs.keys() + if keys: + for k in keys[0:]: + self.set_ref(k, refs[k]) + def set_ref(self, name, value): file = os.path.join(self.controldir(), name) + dirpath = os.path.dirname(file) + if not os.path.exists(dirpath): + os.makedirs(dirpath) f = open(file, 'w') try: f.write(value+"\n")