changeset 396:8f8bb77d560e

Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli. Changes from the original patch: - - Use 'diff -r ...' instead of 'hg diff -r ...' to support filetype detection by at least file(1) and vim. - - Adjusted tests for this change. - - Some cleanups. manifest hash: 5f37d1ef75ea7f4e48b53f02371053ba54fb70f8 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCsyZzW7P1GVgWeRoRAqczAJ479lR9Z289sP+VH5L+N7pQRU14SACfUueq 88ABloIR3VyRIa4qbujnZio= =Vva9 -----END PGP SIGNATURE-----
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 17 Jun 2005 20:37:23 +0100
parents fbe8834923c5
children e5683db23ec4 25afb21d97ba
files contrib/hgit mercurial/commands.py mercurial/mdiff.py tests/test-up-local-change.out
diffstat 4 files changed, 26 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/hgit	Fri Jun 17 11:03:44 2005 -0800
+++ b/contrib/hgit	Fri Jun 17 20:37:23 2005 +0100
@@ -10,7 +10,7 @@
 import time, sys, signal
 from mercurial import hg, mdiff, fancyopts, commands, ui
     
-def difftree(args, repo):
+def difftree(args, ui, repo):
     def __difftree(repo, files = None, node1 = None, node2 = None):
         def date(c):
             return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
@@ -61,7 +61,7 @@
     revs.append(repo.lookup(args[1]))
     args = args[2:]
     if doptions['patch']:
-        commands.dodiff(repo, "", args, *revs)
+        commands.dodiff(ui, repo, "", args, *revs)
     else:
         __difftree(repo, args, *revs)
 
@@ -236,10 +236,10 @@
 repo = hg.repository(ui = u)
 
 if cmd == "diff-tree":
-    difftree(args, repo)
+    difftree(args, u, repo)
 
 elif cmd == "cat-file":
-    catfile(args, ui, repo)
+    catfile(args, u, repo)
 
 elif cmd == "rev-tree":
     revtree(args, repo)
--- a/mercurial/commands.py	Fri Jun 17 11:03:44 2005 -0800
+++ b/mercurial/commands.py	Fri Jun 17 20:37:23 2005 +0100
@@ -32,7 +32,7 @@
         return [ os.path.normpath(os.path.join(p, x)) for x in args ]
     return args
 
-def dodiff(repo, path, files = None, node1 = None, node2 = None):
+def dodiff(ui, repo, path, files = None, node1 = None, node2 = None):
     def date(c):
         return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
 
@@ -49,6 +49,12 @@
             node1 = repo.dirstate.parents()[0]
         def read(f): return file(os.path.join(repo.root, f)).read()
 
+    if ui.quiet:
+        r = None
+    else:
+        hexfunc = ui.verbose and hg.hex or hg.short
+        r = [hexfunc(node) for node in [node1, node2] if node]
+
     change = repo.changelog.read(node1)
     mmap = repo.manifest.read(change[0])
     date1 = date(change)
@@ -61,15 +67,15 @@
         if f in mmap:
             to = repo.file(f).read(mmap[f])
         tn = read(f)
-        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
+        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
     for f in a:
         to = None
         tn = read(f)
-        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
+        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
     for f in d:
         to = repo.file(f).read(mmap[f])
         tn = None
-        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
+        sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
 
 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None):
     """show a single changeset or file revision"""
@@ -290,7 +296,7 @@
     revs = []
     if opts['rev']:
         revs = map(lambda x: repo.lookup(x), opts['rev'])
-    
+
     if len(revs) > 2:
         self.ui.warn("too many revisions to diff\n")
         sys.exit(1)
@@ -300,7 +306,7 @@
     else:
         files = relpath(repo, [""])
 
-    dodiff(repo, os.getcwd(), files, *revs)
+    dodiff(ui, repo, os.getcwd(), files, *revs)
 
 def export(ui, repo, changeset):
     """dump the changeset header and diffs for a revision"""
@@ -316,8 +322,8 @@
         print "# Parent  %s" % hg.hex(other)
     print change[4].rstrip()
     print
-    
-    dodiff(repo, "", None, prev, node)
+
+    dodiff(ui, repo, "", None, prev, node)
 
 def forget(ui, repo, file, *files):
     """don't add the specified files on the next commit"""
--- a/mercurial/mdiff.py	Fri Jun 17 11:03:44 2005 -0800
+++ b/mercurial/mdiff.py	Fri Jun 17 20:37:23 2005 +0100
@@ -8,7 +8,8 @@
 import difflib, struct
 from mercurial.mpatch import *
 
-def unidiff(a, ad, b, bd, fn):
+def unidiff(a, ad, b, bd, fn, r=None):
+
     if not a and not b: return ""
 
     if a == None:
@@ -36,6 +37,10 @@
         if l[ln][-1] != '\n':
             l[ln] += "\n\ No newline at end of file\n"
 
+    if r:
+        l.insert(0, "diff %s %s\n" %
+                    (' '.join(["-r %s" % rev for rev in r]), fn))
+
     return "".join(l)
 
 def textdiff(a, b):
--- a/tests/test-up-local-change.out	Fri Jun 17 11:03:44 2005 -0800
+++ b/tests/test-up-local-change.out	Fri Jun 17 20:37:23 2005 +0100
@@ -12,6 +12,7 @@
 + echo abc
 + hg diff
 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
+diff -r c19d34741b0a a
 --- a/a
 +++ b/a
 @@ -1,1 +1,1 @@
@@ -65,6 +66,7 @@
 
 + hg diff
 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
+diff -r 1e71731e6fbb a
 --- a/a
 +++ b/a
 @@ -1,1 +1,1 @@