[PATCH] Kludge to use --git format patch in hg log

Alexis S. L. Carvalho alexis at cecm.usp.br
Sat Feb 17 08:05:18 UTC 2007


Thus spake tailgunner at smtp.ru:
> Add -g/--git option to "hg log" to get sensible diff of renamed files

There's the general question of whether all commands that print diffs
should get a --git option.  This patch would make it trivial to add
--git to all commands that use cmdutil.show_changeset (tip, heads,
incoming, outgoing, ...).  Do we want that?

Just one thing about the patch itself:

> diff -r cc08d2543593 -r 0a593b528bd7 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Tue Jan 23 17:41:53 2007 -0600
> +++ b/mercurial/cmdutil.py	Wed Feb 14 01:05:09 2007 +0300
> @@ -196,7 +196,7 @@ class changeset_printer(object):
>  class changeset_printer(object):
>      '''show changeset information when templating not requested.'''
>  
> -    def __init__(self, ui, repo, patch, buffered):
> +    def __init__(self, ui, repo, patch, buffered, gitstyle=False):
>          self.ui = ui
>          self.repo = repo
>          self.buffered = buffered
> @@ -204,6 +204,7 @@ class changeset_printer(object):
>          self.header = {}
>          self.hunk = {}
>          self.lastheader = None
> +        self.gitstyle = gitstyle
>  
>      def flush(self, rev):
>          if rev in self.header:
> @@ -305,14 +306,18 @@ class changeset_printer(object):
>      def showpatch(self, node):
>          if self.patch:
>              prev = self.repo.changelog.parents(node)[0]
> -            patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui)
> +            opts = mdiff.diffopts()
> +            if self.gitstyle:
> +                opts.git = True

Instead of passing a gitstyle boolean from show_changeset and calling
mdiff.diffopts here, I think it'd be better to, if we're going to
display a patch, call patch.diffopts(ui, opts) in show_changeset and
pass the full diffopts object to changeset_printer/changeset_templater.

Using patch.diffopts instead of mdiff.diffopts allows us to respect the
[diff] section from config files.

Alexis



More information about the Mercurial-devel mailing list