##// END OF EJS Templates
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli....
Thomas Arendsen Hein -
r396:8f8bb77d default
parent child Browse files
Show More
@@ -10,7 +10,7 b''
10 import time, sys, signal
10 import time, sys, signal
11 from mercurial import hg, mdiff, fancyopts, commands, ui
11 from mercurial import hg, mdiff, fancyopts, commands, ui
12
12
13 def difftree(args, repo):
13 def difftree(args, ui, repo):
14 def __difftree(repo, files = None, node1 = None, node2 = None):
14 def __difftree(repo, files = None, node1 = None, node2 = None):
15 def date(c):
15 def date(c):
16 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
16 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
@@ -61,7 +61,7 b' def difftree(args, repo):'
61 revs.append(repo.lookup(args[1]))
61 revs.append(repo.lookup(args[1]))
62 args = args[2:]
62 args = args[2:]
63 if doptions['patch']:
63 if doptions['patch']:
64 commands.dodiff(repo, "", args, *revs)
64 commands.dodiff(ui, repo, "", args, *revs)
65 else:
65 else:
66 __difftree(repo, args, *revs)
66 __difftree(repo, args, *revs)
67
67
@@ -236,10 +236,10 b' signal.signal(signal.SIGTERM, catchterm)'
236 repo = hg.repository(ui = u)
236 repo = hg.repository(ui = u)
237
237
238 if cmd == "diff-tree":
238 if cmd == "diff-tree":
239 difftree(args, repo)
239 difftree(args, u, repo)
240
240
241 elif cmd == "cat-file":
241 elif cmd == "cat-file":
242 catfile(args, ui, repo)
242 catfile(args, u, repo)
243
243
244 elif cmd == "rev-tree":
244 elif cmd == "rev-tree":
245 revtree(args, repo)
245 revtree(args, repo)
@@ -32,7 +32,7 b' def relpath(repo, args):'
32 return [ os.path.normpath(os.path.join(p, x)) for x in args ]
32 return [ os.path.normpath(os.path.join(p, x)) for x in args ]
33 return args
33 return args
34
34
35 def dodiff(repo, path, files = None, node1 = None, node2 = None):
35 def dodiff(ui, repo, path, files = None, node1 = None, node2 = None):
36 def date(c):
36 def date(c):
37 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
37 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
38
38
@@ -49,6 +49,12 b' def dodiff(repo, path, files = None, nod'
49 node1 = repo.dirstate.parents()[0]
49 node1 = repo.dirstate.parents()[0]
50 def read(f): return file(os.path.join(repo.root, f)).read()
50 def read(f): return file(os.path.join(repo.root, f)).read()
51
51
52 if ui.quiet:
53 r = None
54 else:
55 hexfunc = ui.verbose and hg.hex or hg.short
56 r = [hexfunc(node) for node in [node1, node2] if node]
57
52 change = repo.changelog.read(node1)
58 change = repo.changelog.read(node1)
53 mmap = repo.manifest.read(change[0])
59 mmap = repo.manifest.read(change[0])
54 date1 = date(change)
60 date1 = date(change)
@@ -61,15 +67,15 b' def dodiff(repo, path, files = None, nod'
61 if f in mmap:
67 if f in mmap:
62 to = repo.file(f).read(mmap[f])
68 to = repo.file(f).read(mmap[f])
63 tn = read(f)
69 tn = read(f)
64 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
70 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
65 for f in a:
71 for f in a:
66 to = None
72 to = None
67 tn = read(f)
73 tn = read(f)
68 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
74 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
69 for f in d:
75 for f in d:
70 to = repo.file(f).read(mmap[f])
76 to = repo.file(f).read(mmap[f])
71 tn = None
77 tn = None
72 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
78 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f, r))
73
79
74 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None):
80 def show_changeset(ui, repo, rev=0, changenode=None, filelog=None):
75 """show a single changeset or file revision"""
81 """show a single changeset or file revision"""
@@ -300,7 +306,7 b' def diff(ui, repo, *files, **opts):'
300 else:
306 else:
301 files = relpath(repo, [""])
307 files = relpath(repo, [""])
302
308
303 dodiff(repo, os.getcwd(), files, *revs)
309 dodiff(ui, repo, os.getcwd(), files, *revs)
304
310
305 def export(ui, repo, changeset):
311 def export(ui, repo, changeset):
306 """dump the changeset header and diffs for a revision"""
312 """dump the changeset header and diffs for a revision"""
@@ -317,7 +323,7 b' def export(ui, repo, changeset):'
317 print change[4].rstrip()
323 print change[4].rstrip()
318 print
324 print
319
325
320 dodiff(repo, "", None, prev, node)
326 dodiff(ui, repo, "", None, prev, node)
321
327
322 def forget(ui, repo, file, *files):
328 def forget(ui, repo, file, *files):
323 """don't add the specified files on the next commit"""
329 """don't add the specified files on the next commit"""
@@ -8,7 +8,8 b''
8 import difflib, struct
8 import difflib, struct
9 from mercurial.mpatch import *
9 from mercurial.mpatch import *
10
10
11 def unidiff(a, ad, b, bd, fn):
11 def unidiff(a, ad, b, bd, fn, r=None):
12
12 if not a and not b: return ""
13 if not a and not b: return ""
13
14
14 if a == None:
15 if a == None:
@@ -36,6 +37,10 b' def unidiff(a, ad, b, bd, fn):'
36 if l[ln][-1] != '\n':
37 if l[ln][-1] != '\n':
37 l[ln] += "\n\ No newline at end of file\n"
38 l[ln] += "\n\ No newline at end of file\n"
38
39
40 if r:
41 l.insert(0, "diff %s %s\n" %
42 (' '.join(["-r %s" % rev for rev in r]), fn))
43
39 return "".join(l)
44 return "".join(l)
40
45
41 def textdiff(a, b):
46 def textdiff(a, b):
@@ -12,6 +12,7 b''
12 + echo abc
12 + echo abc
13 + hg diff
13 + hg diff
14 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
14 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
15 diff -r c19d34741b0a a
15 --- a/a
16 --- a/a
16 +++ b/a
17 +++ b/a
17 @@ -1,1 +1,1 @@
18 @@ -1,1 +1,1 @@
@@ -65,6 +66,7 b' 1'
65
66
66 + hg diff
67 + hg diff
67 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
68 + sed 's/\(\(---\|+++\).*\)\t.*/\1/'
69 diff -r 1e71731e6fbb a
68 --- a/a
70 --- a/a
69 +++ b/a
71 +++ b/a
70 @@ -1,1 +1,1 @@
72 @@ -1,1 +1,1 @@
General Comments 0
You need to be logged in to leave comments. Login now