Mercurial > hg > hg-git
changeset 26:a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
author | Scott Chacon <schacon@gmail.com> |
---|---|
date | Mon, 27 Apr 2009 23:35:49 -0700 |
parents | 88e9e9e1caf1 |
children | dc12a36a8d2b |
files | dulwich/client.py dulwich/repo.py git_handler.py |
diffstat | 3 files changed, 40 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/dulwich/client.py +++ b/dulwich/client.py @@ -191,13 +191,13 @@ self.host = host super(TCPGitClient, self).__init__(lambda: _fileno_can_read(self._socket.fileno()), self.rfile.read, self.wfile.write, *args, **kwargs) - def send_pack(self, path): + def send_pack(self, path, generate_pack_contents): """Send a pack to a remote host. :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) + super(TCPGitClient, self).send_pack(path, generate_pack_contents) def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress): """Fetch a pack from the remote host. @@ -232,9 +232,9 @@ self.proc.stdin.flush() return GitClient(lambda: _fileno_can_read(self.proc.stdout.fileno()), read_fn, write_fn, *args, **kwargs) - def send_pack(self, path): + def send_pack(self, path, generate_pack_contents): client = self._connect("git-receive-pack", path) - client.send_pack(path) + client.send_pack(path, generate_pack_contents) def fetch_pack(self, path, determine_wants, graph_walker, pack_data, progress): @@ -287,13 +287,13 @@ self._args = args self._kwargs = kwargs - def send_pack(self, path): - remote = get_ssh_vendor().connect_ssh(self.host, ["git-receive-pack %s" % path], port=self.port) + def send_pack(self, path, 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) + client.send_pack(path, 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) + 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) return client.fetch_pack(path, determine_wants, graph_walker, pack_data, progress)
--- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -244,8 +244,12 @@ ref_name = k parts = k.split('/') if parts[0] == 'refs': # strip off 'refs/heads' - ref_name = "/".join([v for v in parts[2:]]) - self.set_ref('refs/remotes/' + remote_name + '/' + ref_name, refs[k]) + if parts[1] == 'heads': + ref_name = "/".join([v for v in parts[2:]]) + self.set_ref('refs/remotes/' + remote_name + '/' + ref_name, refs[k]) + if parts[1] == 'tags': + ref_name = "/".join([v for v in parts[2:]]) + self.set_ref('refs/tags/' + ref_name, refs[k]) def set_refs(self, refs): keys = refs.keys()
--- a/git_handler.py +++ b/git_handler.py @@ -251,8 +251,20 @@ return None def upload_pack(self, remote_name): - self.ui.status(_("upload pack\n")) - + git_url = self.remote_name_to_url(remote_name) + client, path = self.get_transport_and_path(git_url) + genpack = self.generate_pack_contents + try: + client.send_pack(path, genpack) + # TODO : self.git.set_remote_refs(refs, remote_name) + except: + raise + + def generate_pack_contents(self, want, have, none): + print "WANT: " + str(want) + print "HAVE: " + str(have) + print "NONE: " + str(none) + def fetch_pack(self, remote_name): git_url = self.remote_name_to_url(remote_name) client, path = self.get_transport_and_path(git_url) @@ -287,9 +299,12 @@ if sha in done: continue done.add(sha) - commit = self.git.commit(sha) - convert_list[sha] = commit - todo.extend([p for p in commit.parents if p not in done]) + try: + commit = self.git.commit(sha) + convert_list[sha] = commit + todo.extend([p for p in commit.parents if p not in done]) + except: + print "Cannot import tags yet" # TODO # sort the commits commits = TopoSort(convert_list).items() @@ -358,14 +373,16 @@ def get_transport_and_path(self, uri): from dulwich.client import TCPGitClient, SSHGitClient, SubprocessGitClient - for handler, transport in (("git://", TCPGitClient), ("git+ssh://", SSHGitClient)): + for handler, transport in (("git://", TCPGitClient), ("git@", SSHGitClient)): if uri.startswith(handler): - host, path = uri[len(handler):].split("/", 1) - return transport(host), "/"+path + host, path = uri[len(handler):].split(":", 1) + if handler == 'git@': + host = 'git@' + host + return transport(host), '/' + path # if its not git or git+ssh, try a local url.. return SubprocessGitClient(), uri - +'' """ Tarjan's algorithm and topological sorting implementation in Python by Paul Harrison