# HG changeset patch # User David M. Carr <david@carrclan.us> # Date 1357454817 18000 # Sun Jan 06 01:46:57 2013 -0500 # Node ID 163c452531cf15ed317edc01178443e417643adf # Parent 2320ab6ada364053848ae69cb07a61b1fce1aaba push: add more output about what was added (issue #64) l33t pointed out that currently, Hg-Git doesn't provide any confirmation that a push was successful other than the exit code. Normal Mercurial provides a couple other messages followed by "added X changesets with Y changes to Z files". After this change, Hg-Git will provide much more similar output. It's not identical, as the underlying model is substantially different, but the concept is the same. The main message is "added X commits with Y trees and Z blobs". This change doesn't affect the output of what references/branches were touched. That will be addressed in a subsequent commit. Dulwich doesn't provide an easy hook to get the information needed for this output. Instead of passing generate_pack_contents as the pack generator function to send_pack, I pass a custom function that determines the "missing" objects, stores the counts, and then calls generate_pack_contents (which then will determine the "missing" objects again. The new expected output: searching for changes # unless quiet true <N> commits found # if verbose true list of commits: # if debugflag true and at least one commit found <each hash> # if debugflag true and at least one commit found adding objects # if at least one commit found unless quiet true added <N> commits with <N> trees and <N> blobs # if at least one object unless # quiet true https://bitbucket.org/durin42/hg-git/issue/64/push-confirmation diff --git a/hggit/git_handler.py b/hggit/git_handler.py --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -871,16 +871,40 @@ def upload_pack(self, remote, revs, force): client, path = self.get_transport_and_path(remote) old_refs = {} + change_totals = {} + def changed(refs): + self.ui.status(_("searching for changes\n")) old_refs.update(refs) to_push = revs or set(self.local_heads().values() + self.tags.values()) return self.get_changed_refs(refs, to_push, force) - genpack = self.git.object_store.generate_pack_contents + def genpack(have, want): + commits = [] + for mo in self.git.object_store.find_missing_objects(have, want): + (sha, name) = mo + o = self.git.object_store[sha] + t = type(o) + change_totals[t] = change_totals.get(t, 0) + 1 + if isinstance(o, Commit): + commits.append(sha) + commit_count = len(commits) + self.ui.note(_("%d commits found\n") % commit_count) + if commit_count > 0: + self.ui.debug(_("list of commits:\n")) + for commit in commits: + self.ui.debug("%s\n" % commit) + self.ui.status(_("adding objects\n")) + return self.git.object_store.generate_pack_contents(have, want) + try: - self.ui.status(_("searching for changes\n")) - self.ui.note(_("creating and sending data\n")) new_refs = client.send_pack(path, changed, genpack) + if len(change_totals) > 0: + self.ui.status(_("added %d commits with %d trees" + " and %d blobs\n") % + (change_totals.get(Commit, 0), + change_totals.get(Tree, 0), + change_totals.get(Blob, 0))) return old_refs, new_refs except (HangupException, GitProtocolError), e: raise hgutil.Abort(_("git remote error: ") + str(e)) diff --git a/tests/test-conflict-1.t b/tests/test-conflict-1.t --- a/tests/test-conflict-1.t +++ b/tests/test-conflict-1.t @@ -50,6 +50,8 @@ $ hg push -r master ../gitrepo pushing to ../gitrepo searching for changes + adding objects + added 4 commits with 3 trees and 3 blobs $ cd .. $ hg clone gitrepo hgrepo2 | grep -v '^updating' diff --git a/tests/test-conflict-2.t b/tests/test-conflict-2.t --- a/tests/test-conflict-2.t +++ b/tests/test-conflict-2.t @@ -50,6 +50,8 @@ $ hg push -r master ../gitrepo pushing to ../gitrepo searching for changes + adding objects + added 4 commits with 3 trees and 3 blobs $ cd .. $ hg clone gitrepo hgrepo2 | grep -v '^updating' diff --git a/tests/test-convergedmerge.t b/tests/test-convergedmerge.t --- a/tests/test-convergedmerge.t +++ b/tests/test-convergedmerge.t @@ -51,6 +51,8 @@ $ hg push -r master ../gitrepo pushing to ../gitrepo searching for changes + adding objects + added 5 commits with 3 trees and 3 blobs $ cd .. $ hg clone gitrepo hgrepo2 | grep -v '^updating' diff --git a/tests/test-empty-working-tree.t b/tests/test-empty-working-tree.t --- a/tests/test-empty-working-tree.t +++ b/tests/test-empty-working-tree.t @@ -22,6 +22,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 1 commits with 1 trees and 0 blobs $ cd .. $ git --git-dir=gitrepo2 log --pretty=medium commit 678256865a8c85ae925bf834369264193c88f8de diff --git a/tests/test-encoding.t b/tests/test-encoding.t --- a/tests/test-encoding.t +++ b/tests/test-encoding.t @@ -94,6 +94,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 4 commits with 4 trees and 4 blobs $ cd .. Latin1 commit messages started being automatically converted to UTF-8 in diff --git a/tests/test-file-removal.t b/tests/test-file-removal.t --- a/tests/test-file-removal.t +++ b/tests/test-file-removal.t @@ -75,6 +75,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 5 commits with 6 trees and 3 blobs $ cd .. $ git --git-dir=gitrepo2 log --pretty=medium diff --git a/tests/test-git-tags.t b/tests/test-git-tags.t --- a/tests/test-git-tags.t +++ b/tests/test-git-tags.t @@ -41,5 +41,7 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ cd .. diff --git a/tests/test-hg-author.t b/tests/test-hg-author.t --- a/tests/test-hg-author.t +++ b/tests/test-hg-author.t @@ -24,12 +24,16 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo gamma >> beta $ fn_hg_commit -u "test <test@example.com> (comment)" -m 'modify beta' $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo gamma > gamma $ hg add gamma @@ -37,6 +41,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo delta > delta $ hg add delta @@ -44,6 +50,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo epsilon > epsilon $ hg add epsilon @@ -51,6 +59,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo zeta > zeta $ hg add zeta @@ -58,6 +68,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo eta > eta $ hg add eta @@ -65,6 +77,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ echo theta > theta $ hg add theta @@ -72,6 +86,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ hg log --graph | egrep -v ': *(not-master|master)' @ changeset: 8:d3c51ce68cfd diff --git a/tests/test-hg-branch.t b/tests/test-hg-branch.t --- a/tests/test-hg-branch.t +++ b/tests/test-hg-branch.t @@ -23,6 +23,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 0 blobs $ hg branch gamma | grep -v 'permanent and global' marked working directory as branch gamma @@ -30,6 +32,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 0 blobs $ hg log --graph | egrep -v ': *(not-master|master)' @ changeset: 2:05aed681ccb3 diff --git a/tests/test-hg-tags.t b/tests/test-hg-tags.t --- a/tests/test-hg-tags.t +++ b/tests/test-hg-tags.t @@ -22,6 +22,8 @@ $ hg push pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ hg log --graph | egrep -v ': *(not-master|master)' @ changeset: 1:d529e9229f6d diff --git a/tests/test-merge.t b/tests/test-merge.t --- a/tests/test-merge.t +++ b/tests/test-merge.t @@ -42,6 +42,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 4 commits with 4 trees and 3 blobs $ cd .. git log in repo pushed from hg diff --git a/tests/test-octopus.t b/tests/test-octopus.t --- a/tests/test-octopus.t +++ b/tests/test-octopus.t @@ -69,6 +69,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 5 commits with 5 trees and 4 blobs $ cd .. $ git --git-dir=gitrepo2 log --pretty=medium | sed s/\\.\\.\\.//g diff --git a/tests/test-push.t b/tests/test-push.t --- a/tests/test-push.t +++ b/tests/test-push.t @@ -29,6 +29,8 @@ $ hg push -r beta pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs $ cd .. @@ -100,6 +102,8 @@ $ hg push -fr master pushing to $TESTTMP/gitrepo searching for changes + adding objects + added 1 commits with 1 trees and 1 blobs this should fail, no changes to push The exit code for this was broken in Mercurial (incorrectly returning 0) until diff --git a/tests/test-subrepos.t b/tests/test-subrepos.t --- a/tests/test-subrepos.t +++ b/tests/test-subrepos.t @@ -72,6 +72,8 @@ $ hg push pushing to $TESTTMP/gitrepo1 searching for changes + adding objects + added 1 commits with 2 trees and 1 blobs $ cd .. $ cd gitrepo1 there shall be two gitlink entries, with values matching that in .hgsubstate diff --git a/tests/test-tree-decomposition.t b/tests/test-tree-decomposition.t --- a/tests/test-tree-decomposition.t +++ b/tests/test-tree-decomposition.t @@ -41,6 +41,8 @@ $ hg push ../gitrepo2 pushing to ../gitrepo2 searching for changes + adding objects + added 3 commits with 6 trees and 3 blobs $ cd .. $ git --git-dir=gitrepo2 log --pretty=medium