views:

385

answers:

2

I do a lot of code reviews mostly using "hg in -p /path/to/repo" command and it would be very nice if its output could be viewed in some external program(e.g vimdiff). Is there any way to achieve that?

+1  A: 

My quick-and-dirty first answer was: "See the Extdiff extension, distributed with mercurial and documented on their site." Which was really only about 15% of the answer.

The closest answer I've seen so far starts with an extension called rdiff. rdiff uses the 'incoming' code and so addresses that half of your question. This extension was mentioned in an earlier SO thread which gives an example of a bash script to implement an rdiff against the current working copy (as opposed to the current repository copy). The script ends up using "hg diff", so it would be affected by whatever you have extdiff set to.

rdiff.py is only 146 lines and reasonably comprehensible, and the bash script is 5 lines long. Although not a complete answer to your question, I think it points the way.

Peter Rowell
Please correct me if I'm wrong, but extdiff only works with your own local changes. It seems it can't be used with 'incoming/outgoing' commands...
pachanga
You're right -- I didn't really read your question. In doing some research (which I should have done before I answered) it looks like "hooks" may contain the beginning of the answer. I am currently reading http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html with your question in mind. I'll edit my answer if I find something worthwhile.
Peter Rowell
A: 

I asked the same question on the mercurial mailing list and got some interesting suggestions. The best one I liked came from Matt Mackall which boils down to:

1) use "hg incoming --bundle in.hg" to save a bundle of incoming changes

2) use "hg -R in.hg extdiff" to view the changes

While this sounds like a good idea, unfortunately, I'm getting an exception:

pachanga@kurluka $ hg -R /tmp/in.bundle extdiff
** unknown exception encountered, details follow
** report bug details to http://www.selenic.com/mercurial/bts
** or [email protected]
** Mercurial Distributed SCM (version 1.1.2)
** Extensions loaded: alias, fetch, extdiff, graphlog, hgk, rdiff
Traceback (most recent call last):
 File "/usr/bin/hg", line 20, in <module>
   mercurial.dispatch.run()
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
20, in run
   sys.exit(dispatch(sys.argv[1:]))
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
29, in dispatch
   return _runcatch(u, args)
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
45, in _runcatch
   return _dispatch(ui, args)
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
367, in _dispatch
   ret = _runcommand(ui, options, cmd, d)
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
416, in _runcommand
   return checkargs()
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
376, in checkargs
   return cmdfunc()
 File "/var/lib/python-support/python2.6/mercurial/dispatch.py", line
361, in <lambda>
   d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
 File "/var/lib/python-support/python2.6/mercurial/util.py", line 715, in check
   return func(*args, **kwargs)
 File "/var/lib/python-support/python2.6/hgext/extdiff.py", line 203,
in extdiff
   return dodiff(ui, repo, program, option, pats, opts)
 File "/var/lib/python-support/python2.6/hgext/extdiff.py", line 123, in dodiff
   node1, node2 = cmdutil.revpair(repo, opts['rev'])
 File "/var/lib/python-support/python2.6/mercurial/cmdutil.py", line
123, in revpair
   return repo.dirstate.parents()[0], None
 File "/var/lib/python-support/python2.6/mercurial/bundlerepo.py",
line 229, in __getattr__
   raise AttributeError(name)
AttributeError: dirstate

I posted this error to the mailing list as well but got no replies so far...

pachanga