diff --git a/git_handler.py b/git_handler.py index 68927eea19..dcaff50768 100644 --- a/git_handler.py +++ b/git_handler.py @@ -123,6 +123,29 @@ class GitHandler(object): self.update_references() self.save_map() + def get_refs(self, remote): + self.export_commits() + client, path = self.get_transport_and_path(remote) + old_refs = {} + new_refs = {} + def changed(refs): + old_refs.update(refs) + to_push = set(self.local_heads().values() + self.tags.values()) + if not to_push and refs.keys()[0] == 'capabilities^{}': + to_push = [self.repo.lookup('tip')] + new_refs.update(self.get_changed_refs(refs, to_push, True)) + # don't push anything + return {} + + try: + client.send_pack(path, changed, None) + new = [bin(self.map_hg_get(r)) for r in new_refs.values()] + old = dict((bin(self.map_hg_get(r)), 1) for r in old_refs.values()) + + return old, new + except HangupException: + raise hgutil.Abort("the remote end hung up unexpectedly") + def push(self, remote, revs, force): self.export_commits() changed_refs = self.upload_pack(remote, revs, force) @@ -134,7 +157,6 @@ class GitHandler(object): self.update_remote_branches(remote_name, changed_refs) - def clear(self): mapfile = self.repo.join(self.mapfile) if os.path.exists(self.gitdir): diff --git a/hgrepo.py b/hgrepo.py index 7beac4f461..f8b5b158e8 100644 --- a/hgrepo.py +++ b/hgrepo.py @@ -24,6 +24,15 @@ def generate_repo_subclass(baseclass): else: #pragma: no cover return super(hgrepo, self).push(remote, force, revs) + def findoutgoing(self, remote, base=None, heads=None, force=False): + if isinstance(remote, gitrepo): + git = GitHandler(self, self.ui) + base, heads = git.get_refs(remote.path) + out, h = super(hgrepo, self).findoutgoing(remote, base, heads, force) + return out + else: #pragma: no cover + return super(hgrepo, self).findoutgoing(remote, base, heads, force) + def tags(self): if self.tagscache: return self.tagscache diff --git a/tests/test-outgoing b/tests/test-outgoing new file mode 100755 index 0000000000..2e769c7140 --- /dev/null +++ b/tests/test-outgoing @@ -0,0 +1,94 @@ +#!/bin/sh + +# Fails for some reason, need to investigate +# "$TESTDIR/hghave" git || exit 80 + +# bail early if the user is already running git-daemon +echo hi | nc localhost 9418 2>/dev/null && exit 80 + +echo "[extensions]" >> $HGRCPATH +echo "hggit=$(echo $(dirname $(dirname $0)))" >> $HGRCPATH +echo 'hgext.graphlog =' >> $HGRCPATH +echo 'hgext.bookmarks =' >> $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 "hg 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` +} + +mkdir gitrepo +cd gitrepo +git init | python -c "import sys; print sys.stdin.read().replace('$(dirname $(pwd))/', '')" + +echo alpha > alpha +git add alpha +commit -m "add alpha" + +# dulwich does not presently support local git repos, workaround +cd .. +git daemon --base-path="$(pwd)"\ + --listen=localhost\ + --export-all\ + --pid-file=gitdaemon.pid \ + --detach --reuseaddr \ + --enable=receive-pack + +hg clone git://localhost/gitrepo hgrepo + +cd hgrepo +echo beta > beta +hg add beta +hgcommit -m 'add beta' + + +echo gamma > gamma +hg add gamma +hgcommit -m 'add gamma' + +hg book -r 1 beta + +hg outgoing +hg outgoing -r beta +hg outgoing -r master + +cd .. + +echo % some more work on master from git +cd gitrepo + +git checkout master +echo delta > delta +git add delta +commit -m "add delta" + +cd .. + +cd hgrepo +echo % this will fail # maybe we should try to make it work +hg outgoing +echo % let\'s pull and try again +hg pull +hg outgoing +hg outgoing -r beta +hg outgoing -r master + + +cd .. +kill `cat gitdaemon.pid` diff --git a/tests/test-outgoing.out b/tests/test-outgoing.out new file mode 100644 index 0000000000..0b63ad4cb0 --- /dev/null +++ b/tests/test-outgoing.out @@ -0,0 +1,99 @@ +Initialized empty Git repository in gitrepo/.git/ + +importing Hg objects into Git +Counting objects: 3, done. +Total 3 (delta 0), reused 0 (delta 0) +importing Git objects into Hg +at: 0/1 +updating working directory +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +comparing with git://localhost/gitrepo +importing Hg objects into Git +at: 0/2 +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +changeset: 2:72f56395749d +tag: master +tag: tip +user: test +date: Mon Jan 01 00:00:12 2007 +0000 +summary: add gamma + +comparing with git://localhost/gitrepo +importing Hg objects into Git +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +comparing with git://localhost/gitrepo +importing Hg objects into Git +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +changeset: 2:72f56395749d +tag: master +tag: tip +user: test +date: Mon Jan 01 00:00:12 2007 +0000 +summary: add gamma + +% some more work on master from git +Already on "master" +% this will fail +comparing with git://localhost/gitrepo +importing Hg objects into Git +abort: refs/heads/master changed on the server, please pull and merge before pushing +% let's pull and try again +pulling from git://localhost/gitrepo +importing Hg objects into Git +Counting objects: 4, done. +Compressing objects: 50% (1/2) Compressing objects: 100% (2/2) Compressing objects: 100% (2/2), done. +Total 3 (delta 0), reused 0 (delta 0) +importing Git objects into Hg +at: 0/1 +(run 'hg update' to get a working copy) +comparing with git://localhost/gitrepo +importing Hg objects into Git +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +changeset: 2:72f56395749d +tag: master +user: test +date: Mon Jan 01 00:00:12 2007 +0000 +summary: add gamma + +comparing with git://localhost/gitrepo +importing Hg objects into Git +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +comparing with git://localhost/gitrepo +importing Hg objects into Git +changeset: 1:0564f526fb0f +tag: beta +user: test +date: Mon Jan 01 00:00:11 2007 +0000 +summary: add beta + +changeset: 2:72f56395749d +tag: master +user: test +date: Mon Jan 01 00:00:12 2007 +0000 +summary: add gamma +