[PATCH 1 of 2 next] push: add more output about what was added (issue #64)

20 views
Skip to first unread message

David Carr

unread,
Jan 6, 2013, 2:32:26 AM1/6/13
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1357454817 18000
# 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 <te...@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

David Carr

unread,
Jan 6, 2013, 2:32:27 AM1/6/13
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1357457497 18000
# Node ID a6b7ad535244444be00ffd3795fd468ced5932f9
# Parent 163c452531cf15ed317edc01178443e417643adf
push: provide better output about changed references (issue #64)

As pointed out by l33t, Hg-Git's output for push doesn't currently do a very
good job of telling the user what happened. My previous changes in this area
had moved some of the output from status to note, making it only show if
--verbose was specified. However, I hadn't realized at the time that the
reference information (though overly verbose) was providing a valueable purpose
that otherwise wasn't met; telling the user that a remote reference had changed.

This changeset makes it so that:
* default output will include simple messages like "adding reference
refs/heads/feature" and "updating reference refs/heads/master" (omitting any
mention of unchanged references)
* verbose output will include more detailed messages like "adding reference
default::refs/heads/feature => GIT:aba43c" and "updating reference
default::refs/heads/master => GIT:aba43c" (omitting any mention of unchanged
references)
* debug output will include the detailed output like in verbose, but
addtionally will include messages like "unchanged reference
default::refs/heads/other => GIT:aba43c"

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
@@ -278,11 +278,21 @@

if remote_name and new_refs:
for ref, new_sha in new_refs.iteritems():
- if new_sha != old_refs.get(ref):
- self.ui.note(" %s::%s => GIT:%s\n" %
+ old_sha = old_refs.get(ref)
+ if old_sha is None:
+ if self.ui.verbose:
+ self.ui.note("adding reference %s::%s => GIT:%s\n" %
(remote_name, ref, new_sha[0:8]))
+ else:
+ self.ui.status("adding reference %s\n" % ref)
+ elif new_sha != old_sha:
+ if self.ui.verbose:
+ self.ui.note("updating reference %s::%s => GIT:%s\n" %
+ (remote_name, ref, new_sha[0:8]))
+ else:
+ self.ui.status("updating reference %s\n" % ref)
else:
- self.ui.debug(" %s::%s => GIT:%s\n" %
+ self.ui.debug("unchanged reference %s::%s => GIT:%s\n" %
(remote_name, ref, new_sha[0:8]))

self.update_remote_branches(remote_name, new_refs)
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
@@ -43,5 +43,6 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ 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
@@ -26,6 +26,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo gamma >> beta
$ fn_hg_commit -u "test <te...@example.com> (comment)" -m 'modify beta'
@@ -34,6 +35,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo gamma > gamma
$ hg add gamma
@@ -43,6 +45,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo delta > delta
$ hg add delta
@@ -52,6 +55,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo epsilon > epsilon
$ hg add epsilon
@@ -61,6 +65,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo zeta > zeta
$ hg add zeta
@@ -70,6 +75,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo eta > eta
$ hg add eta
@@ -79,6 +85,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ echo theta > theta
$ hg add theta
@@ -88,6 +95,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

$ 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
@@ -25,6 +25,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 0 blobs
+ updating reference refs/heads/master

$ hg branch gamma | grep -v 'permanent and global'
marked working directory as branch gamma
@@ -34,6 +35,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 0 blobs
+ updating reference refs/heads/master

$ 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
@@ -24,6 +24,8 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ adding reference refs/tags/alpha
+ updating reference refs/heads/master

$ hg log --graph | egrep -v ': *(not-master|master)'
@ changeset: 1:d529e9229f6d
diff --git a/tests/test-push.t b/tests/test-push.t
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -31,6 +31,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ adding reference refs/heads/beta

$ cd ..

@@ -104,6 +105,7 @@
searching for changes
adding objects
added 1 commits with 1 trees and 1 blobs
+ updating reference refs/heads/master

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
@@ -74,6 +74,7 @@
searching for changes
adding objects
added 1 commits with 2 trees and 1 blobs
+ updating reference refs/heads/master

Augie Fackler

unread,
Jan 10, 2013, 2:40:58 PM1/10/13
to hg-...@googlegroups.com
On Sun, Jan 06, 2013 at 02:32:27AM -0500, David Carr wrote:
> # HG changeset patch
> # User David M. Carr <da...@carrclan.us>
> # Date 1357457497 18000
> # Node ID a6b7ad535244444be00ffd3795fd468ced5932f9
> # Parent 163c452531cf15ed317edc01178443e417643adf
> push: provide better output about changed references (issue #64)

Queued both of these, thanks.
> --
> You received this message because you are subscribed to the Google Groups "hg-git" group.
> To post to this group, send email to hg-...@googlegroups.com.
> To unsubscribe from this group, send email to hg-git+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hg-git?hl=en.
>
Reply all
Reply to author
Forward
0 new messages