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

tailgunner at smtp.ru tailgunner at smtp.ru
Thu Feb 15 22:31:32 UTC 2007


Add -g/--git option to "hg log" to get sensible diff of renamed files


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
+            patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui,
+                       opts=opts)
             self.ui.write("\n")
 
 class changeset_templater(changeset_printer):
     '''format changeset information.'''
 
-    def __init__(self, ui, repo, patch, mapfile, buffered):
-        changeset_printer.__init__(self, ui, repo, patch, buffered)
+    def __init__(self, ui, repo, patch, mapfile, buffered, gitstyle=False):
+        changeset_printer.__init__(self, ui, repo, patch, buffered, gitstyle)
         self.t = templater.templater(mapfile, templater.common_filters,
                                      cache={'parent': '{rev}:{node|short} ',
                                             'manifest': '{rev}:{node|short}',
@@ -525,6 +530,10 @@ def show_changeset(ui, repo, opts, buffe
             else:
                 mapfile = ui.config('ui', 'style')
 
+    if opts.get("git"):
+        gitstyle = True
+    else:
+        gitstyle = False
     if tmpl or mapfile:
         if mapfile:
             if not os.path.split(mapfile)[0]:
@@ -532,12 +541,12 @@ def show_changeset(ui, repo, opts, buffe
                            or templater.templatepath(mapfile))
                 if mapname: mapfile = mapname
         try:
-            t = changeset_templater(ui, repo, patch, mapfile, buffered)
+            t = changeset_templater(ui, repo, patch, mapfile, buffered, gitstyle)
         except SyntaxError, inst:
             raise util.Abort(inst.args[0])
         if tmpl: t.use_template(tmpl)
         return t
-    return changeset_printer(ui, repo, patch, buffered)
+    return changeset_printer(ui, repo, patch, buffered, gitstyle)
 
 def finddate(ui, repo, date):
     """Find the tipmost changeset that matches the given date spec"""
diff -r cc08d2543593 -r 0a593b528bd7 mercurial/commands.py
--- a/mercurial/commands.py	Tue Jan 23 17:41:53 2007 -0600
+++ b/mercurial/commands.py	Wed Feb 14 01:05:09 2007 +0300
@@ -2760,6 +2760,7 @@ table = {
            _('follow changeset history, or file history across copies and renames')),
           ('', 'follow-first', None,
            _('only follow the first parent of merge changesets')),
+          ('g', 'git', None, _('use git extended diff format')),
           ('d', 'date', '', _('show revs matching date spec')),
           ('C', 'copies', None, _('show copied files')),
           ('k', 'keyword', [], _('search for a keyword')),




More information about the Mercurial-devel mailing list