This is an archive of the discontinued Mercurial Phabricator instance.

scmutil: add a new function to show changes after a command
AbandonedPublic

Authored by pulkit on Oct 4 2017, 10:34 AM.

Details

Reviewers
dlax
Group Reviewers
hg-reviewers
Summary

This patch adds a new function named showchanges() which will output the changes
like hashchanges, wdir change, movement of bookmarks etc. after a command. This
will be very helpful in automation and will be a good addition to the UI behind
a config. Currently it supports only hash changes for the moment.

The hash changes are form of: {predecessor: [successors], ...}

The successors is a list as there can be multiple successors of a predecessor in
case of split command which is available in evolve and fb-hgext.

Thanks to Denis Laxalde for suggesting the pythonic way to get nodesdict.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

pulkit created this revision.Oct 4 2017, 10:34 AM

@quark I was unable to make 'hashchanges' resolved by templater. I took help from Yuya and he was bit confused on how you want it to be done. (adding @yuja)

dlax added a subscriber: dlax.Oct 4 2017, 10:59 AM

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py

  • a/mercurial/scmutil.py

+++ b/mercurial/scmutil.py
@@ -685,6 +685,18 @@

if tostrip:
    repair.delayedstrip(repo.ui, repo, tostrip, operation)

+def showchanges(replacements, fm):
+ """ output the hash changes using formatter instance which is passed.
+ """
+ nodesdict = {}
+ for pred, succs in replacements.iteritems():
+ succlist = []
+ for succ in succs:
+ succlist.append(short(succ))
+ nodesdict[short(pred)] = succlist
+ fm.write('hashchanges', '%s\n',
+ fm.formatdict(nodesdict, fmt='%r --> %r', sep='\n'))

The indentation looks wrong. Do you really mean to fm.write() on each
iteration?

Also, nodedict could be written using comprehensions:

nodedict = {

short(pred): [short(s) for s in succs]
for pred, succs in replacements.iteritems()

}

+

def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None):
    if opts is None:
        opts = {}
pulkit planned changes to this revision.Oct 4 2017, 11:04 AM
In D933#15594, @dlax wrote:

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py

  • a/mercurial/scmutil.py

+++ b/mercurial/scmutil.py
@@ -685,6 +685,18 @@

if tostrip:
    repair.delayedstrip(repo.ui, repo, tostrip, operation)

+def showchanges(replacements, fm):
+ """ output the hash changes using formatter instance which is passed.
+ """
+ nodesdict = {}
+ for pred, succs in replacements.iteritems():
+ succlist = []
+ for succ in succs:
+ succlist.append(short(succ))
+ nodesdict[short(pred)] = succlist
+ fm.write('hashchanges', '%s\n',
+ fm.formatdict(nodesdict, fmt='%r --> %r', sep='\n'))

The indentation looks wrong. Do you really mean to fm.write() on each
iteration?

Ah, my bad. Thanks for catching.

Also, nodedict could be written using comprehensions:
nodedict = {

short(pred): [short(s) for s in succs]
for pred, succs in replacements.iteritems()

}

Thanks will replace to this is next version.

pulkit edited the summary of this revision. (Show Details)Oct 4 2017, 11:13 AM
pulkit updated this revision to Diff 2418.
dlax added inline comments.Oct 4 2017, 11:20 AM
mercurial/scmutil.py
695

Indentation still weird (though no longer wrong).
Could you align continuation lines with the opening delimiter ({ for nodedict and ( for fm.write)?

pulkit updated this revision to Diff 2420.Oct 4 2017, 11:28 AM
dlax requested changes to this revision.Oct 4 2017, 12:00 PM
dlax added inline comments.
mercurial/scmutil.py
695

A "correct" indentation would be:

nodesdict = {short(pred): [short(s) for s in succs]
             for pred, succs in replacements.iteritems()} 
fm.write('hashchanges', '%s\n',
         fm.formatdict(nodesdict, fmt='%r --> %r', sep='\n'))

Continuation lines should be aligned with the opening delimiter.

This revision now requires changes to proceed.Oct 4 2017, 12:00 PM
pulkit updated this revision to Diff 2427.Oct 4 2017, 2:11 PM
dlax added inline comments.Oct 4 2017, 3:16 PM
mercurial/scmutil.py
695

almost fine, just add an extra space in continuation lines so that they start after the opening delimiter.

pulkit updated this revision to Diff 2458.Oct 5 2017, 5:53 AM
dlax accepted this revision.Oct 5 2017, 5:58 AM

This patch looks good to me. But I have no idea if the overall idea in the series is good or not.

pulkit planned changes to this revision.Oct 6 2017, 5:15 PM
pulkit abandoned this revision.Oct 17 2017, 7:15 PM

Abandoning in favor of D1173.