From 153a216f47b70efa2fc966c2ea9584e56cd6ac27 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 19:24:19 -0500 Subject: [PATCH 1/7] test: main: cleanup big push fetch first In order to use setup_big_push(). No functional changes. Signed-off-by: Felipe Contreras --- test/main.t | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/test/main.t b/test/main.t index 10456ee..8d497b8 100755 --- a/test/main.t +++ b/test/main.t @@ -631,53 +631,23 @@ test_expect_success 'remote big push' ' test_expect_success 'remote big push fetch first' ' test_when_finished "rm -rf hgrepo gitrepo*" && - ( - hg init hgrepo && - cd hgrepo && - echo zero > content && - hg add content && - hg commit -m zero && - hg bookmark bad_bmark && - hg bookmark good_bmark && - hg bookmark -i good_bmark && - hg -q branch good_branch && - echo "good branch" > content && - hg commit -m "good branch" && - hg -q branch bad_branch && - echo "bad branch" > content && - hg commit -m "bad branch" - ) && - - git clone "hg::hgrepo" gitrepo && + setup_big_push ( cd hgrepo && - hg bookmark -f bad_bmark && + hg checkout bad_branch && + hg bookmark -f bad_bmark1 && echo update_bmark > content && hg commit -m "update bmark" ) && ( cd gitrepo && - echo two > content && - git commit -q -a -m two && - - git checkout -q good_bmark && - echo three > content && - git commit -q -a -m three && - - git checkout -q bad_bmark && - echo four > content && - git commit -q -a -m four && - - git checkout -q branches/bad_branch && - echo five > content && - git commit -q -a -m five && check_push 1 --all <<-\EOF && master good_bmark - bad_bmark:fetch-first + bad_bmark1:fetch-first branches/bad_branch:fetch-first EOF @@ -686,7 +656,7 @@ test_expect_success 'remote big push fetch first' ' check_push 1 --all <<-\EOF master good_bmark - bad_bmark:non-fast-forward + bad_bmark1:non-fast-forward branches/bad_branch:non-fast-forward EOF ) From d1544e2ccd60234acb24ac31a3d85b7dce76db5a Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Sat, 9 Jul 2016 09:43:37 +0200 Subject: [PATCH 2/7] test: pushing a bookmark without changesets This works in recent versions of Mercurial. Signed-off-by: Felipe Contreras --- test/main.t | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/main.t b/test/main.t index 8d497b8..888d420 100755 --- a/test/main.t +++ b/test/main.t @@ -853,6 +853,31 @@ test_expect_failure 'push updates notes' ' test_cmp expected actual ' +test_expect_success 'push bookmark without changesets' ' + test_when_finished "rm -rf hgrepo gitrepo" && + + ( + hg init hgrepo && + cd hgrepo && + echo one > content && + hg add content && + hg commit -m one + ) && + + git clone "hg::hgrepo" gitrepo && + + ( + cd gitrepo && + echo two > content && + git commit -a -m two && + git push origin master && + git branch feature-a && + git push origin feature-a + ) && + + check_bookmark hgrepo feature-a two +' + test_expect_unstable 'pull tags' ' test_when_finished "rm -rf hgrepo gitrepo" && From fa3484e08b0f3f3ed15893531632fb86e3858e19 Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Sat, 9 Jul 2016 09:31:37 +0200 Subject: [PATCH 3/7] Find outgoing changesets earlier This way we can find if we actually need to push something. Recent versions of Mercurial already handle this correctly, but let's check ourselves to make sure, and make it work with all versions. Rewritten-by: Felipe Contreras Signed-off-by: Felipe Contreras --- git-remote-hg | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 023bbb4..7e70e40 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -1083,13 +1083,17 @@ def push_unsafe(repo, remote, parsed_refs, p_revs): fci = discovery.findcommonincoming commoninc = fci(repo, remote, force=force) common, _, remoteheads = commoninc + fco = discovery.findcommonoutgoing + outgoing = fco(repo, remote, onlyheads=list(p_revs), commoninc=commoninc, force=force) if not checkheads(repo, remote, p_revs): - return None + return False + + if not outgoing.missing: + # Nothing to push + return True if check_version(4, 0): - from mercurial import exchange - outgoing = exchange._computeoutgoing(repo, list(p_revs), common) if check_version(4, 4): cg = changegroup.makechangegroup(repo, outgoing, '01', 'push') else: From 510441bba96168fb0eabff640f646314f783ed1e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 20 Jun 2019 14:28:29 -0500 Subject: [PATCH 4/7] gitrange(): add a == b check Otherwise we return the whole repository. Thanks to the marks we don't actually export it, but there's no need to return so many revs. Reported-by: Mark Nauwelaerts Signed-off-by: Felipe Contreras --- git-remote-hg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-remote-hg b/git-remote-hg index 7e70e40..58cd5a2 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -473,6 +473,9 @@ def mark_to_rev(mark): # Get a range of revisions in the form of a..b (git committish) def gitrange(repo, a, b): + if a == b: + return [] + positive = [] pending = set([b.rev()]) negative = set([a.rev()]) From fe8b8c1a61a5bf5b473ca1cf6d82d3ae2f5956c8 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 20 Jun 2019 14:31:49 -0500 Subject: [PATCH 5/7] gitrange(): store parentrevs method By calling the methods through a variable the code is significantly faster. Signed-off-by: Felipe Contreras --- git-remote-hg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-remote-hg b/git-remote-hg index 58cd5a2..26c225c 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -476,6 +476,8 @@ def gitrange(repo, a, b): if a == b: return [] + pfunc = repo.changelog.parentrevs + positive = [] pending = set([b.rev()]) negative = set([a.rev()]) @@ -483,7 +485,7 @@ def gitrange(repo, a, b): if not pending: break - parents = [p for p in repo.changelog.parentrevs(cur) if p >= 0] + parents = [p for p in pfunc(cur) if p >= 0] if cur in pending: positive.append(cur) From 1d85449b0b35044da7a53530ea334c983897475c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 20 Jun 2019 14:34:14 -0500 Subject: [PATCH 6/7] gitrange(): always check negatives first Also, always add the parents as negatives. Signed-off-by: Felipe Contreras --- git-remote-hg | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 26c225c..4d15fa4 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -487,19 +487,17 @@ def gitrange(repo, a, b): parents = [p for p in pfunc(cur) if p >= 0] - if cur in pending: + if cur in negative: + negative.remove(cur) + for p in parents: + negative.add(p) + pending.discard(p) + elif cur in pending: positive.append(cur) pending.remove(cur) for p in parents: if p not in negative: pending.add(p) - elif cur in negative: - negative.remove(cur) - for p in parents: - if p not in pending: - negative.add(p) - else: - pending.discard(p) positive.reverse() return positive From 74d1aa14ac19d278720e0326c5fd18cf47d2553e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 20 Jun 2019 14:39:36 -0500 Subject: [PATCH 7/7] gitrange(): general refactoring To make the code more readable. No functional changes. Signed-off-by: Felipe Contreras --- git-remote-hg | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 4d15fa4..c273c95 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -477,25 +477,29 @@ def gitrange(repo, a, b): return [] pfunc = repo.changelog.parentrevs + it = iter(xrange(b.rev(), -1, -1)) positive = [] pending = set([b.rev()]) negative = set([a.rev()]) - for cur in xrange(b.rev(), -1, -1): - if not pending: - break - parents = [p for p in pfunc(cur) if p >= 0] + def get_parents(rev): + for p in pfunc(rev): + if p == -1: continue + yield p + + while pending: + cur = it.next() if cur in negative: negative.remove(cur) - for p in parents: + for p in get_parents(cur): negative.add(p) pending.discard(p) elif cur in pending: positive.append(cur) pending.remove(cur) - for p in parents: + for p in get_parents(cur): if p not in negative: pending.add(p)