##// END OF EJS Templates
Diff in subdirectories from Jake Edge...
mpm@selenic.com -
r64:b3e2ddff default
parent child Browse files
Show More
@@ -48,20 +48,25 b' def filterfiles(list, files):'
48 48 return l
49 49
50 50 def diff(files = None, node1 = None, node2 = None):
51 def date(c):
52 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
51 53
52 54 if node2:
53 55 change = repo.changelog.read(node2)
54 56 mmap2 = repo.manifest.read(change[0])
55 57 (c, a, d) = repo.diffrevs(node1, node2)
56 58 def read(f): return repo.file(f).read(mmap2[f])
59 date2 = date(change)
57 60 else:
61 date2 = time.asctime()
58 62 if not node1:
59 63 node1 = repo.current
60 64 (c, a, d) = repo.diffdir(repo.root, node1)
61 def read(f): return file(f).read()
65 def read(f): return file(os.path.join(repo.root, f)).read()
62 66
63 67 change = repo.changelog.read(node1)
64 68 mmap = repo.manifest.read(change[0])
69 date1 = date(change)
65 70
66 71 if files:
67 72 (c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d))
@@ -69,16 +74,15 b' def diff(files = None, node1 = None, nod'
69 74 for f in c:
70 75 to = repo.file(f).read(mmap[f])
71 76 tn = read(f)
72 sys.stdout.write(mdiff.unidiff(to, tn, f))
77 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
73 78 for f in a:
74 79 to = ""
75 80 tn = read(f)
76 sys.stdout.write(mdiff.unidiff(to, tn, f))
81 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
77 82 for f in d:
78 83 to = repo.file(f).read(mmap[f])
79 84 tn = ""
80 sys.stdout.write(mdiff.unidiff(to, tn, f))
81
85 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
82 86
83 87 options = {}
84 88 opts = [('v', 'verbose', None, 'verbose'),
@@ -178,8 +182,13 b' elif cmd == "diff":'
178 182 if len(revs) > 2:
179 183 print "too many revisions to diff"
180 184 sys.exit(1)
181 else:
182 diff(args, *revs)
185
186 if os.getcwd() != repo.root:
187 relpath = os.getcwd()[len(repo.root) + 1: ]
188 if not args: args = [ relpath ]
189 else: args = [ os.path.join(relpath, x) for x in args ]
190
191 diff(args, *revs)
183 192
184 193 elif cmd == "export":
185 194 node = repo.changelog.lookup(args[0])
@@ -499,7 +499,7 b' class localrepository:'
499 499 dc = dict.fromkeys(mf)
500 500
501 501 def fcmp(fn):
502 t1 = file(fn).read()
502 t1 = file(os.path.join(self.root, fn)).read()
503 503 t2 = self.file(fn).revision(mf[fn])
504 504 return cmp(t1, t2)
505 505
@@ -509,7 +509,7 b' class localrepository:'
509 509
510 510 for f in files:
511 511 fn = os.path.join(d, f)
512 try: s = os.stat(fn)
512 try: s = os.stat(os.path.join(self.root, fn))
513 513 except: continue
514 514 if fn in dc:
515 515 c = dc[fn]
@@ -2,11 +2,11 b''
2 2 import difflib, struct
3 3 from cStringIO import StringIO
4 4
5 def unidiff(a, b, fn):
5 def unidiff(a, ad, b, bd, fn):
6 6 if not a and not b: return ""
7 7 a = a.splitlines(1)
8 8 b = b.splitlines(1)
9 l = list(difflib.unified_diff(a, b, fn, fn))
9 l = list(difflib.unified_diff(a, b, "a/" + fn, "b/" + fn, ad, bd))
10 10 return "".join(l)
11 11
12 12 def textdiff(a, b):
@@ -29,15 +29,11 b' def sortdiff(a, b):'
29 29 la += 1
30 30 lb += 1
31 31
32 si = lb
33 while lb < len(b):
34 lb += 1
35 yield "insert", la, la, si, lb
32 if lb < len(b):
33 yield "insert", la, la, lb, len(b)
36 34
37 si = la
38 while la < len(a):
39 la += 1
40 yield "delete", si, la, lb, lb
35 if la < len(a):
36 yield "delete", la, len(a), lb, lb
41 37
42 38 def diff(a, b, sorted=0):
43 39 bin = []
@@ -60,6 +56,7 b' def patch(a, bin):'
60 56 last = pos = 0
61 57 r = []
62 58
59 c = 0
63 60 while pos < len(bin):
64 61 p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
65 62 pos += 12
@@ -67,6 +64,7 b' def patch(a, bin):'
67 64 r.append(bin[pos:pos + l])
68 65 pos += l
69 66 last = p2
67 c += 1
70 68 r.append(a[last:])
71 69
72 70 return "".join(r)
@@ -114,7 +114,7 b' class revlog:'
114 114 last = self.length(base)
115 115 text = decompress(data[:last])
116 116
117 for r in range(base + 1, rev + 1):
117 for r in xrange(base + 1, rev + 1):
118 118 s = self.length(r)
119 119 b = decompress(data[last:last + s])
120 120 text = self.patch(text, b)
@@ -138,14 +138,16 b' class revlog:'
138 138 t = n - 1
139 139
140 140 if n:
141 start = self.start(self.base(t))
141 base = self.base(t)
142 start = self.start(base)
142 143 end = self.end(t)
143 144 prev = self.revision(self.tip())
144 145 data = compress(self.diff(prev, text))
146 dist = end - start + len(data)
145 147
146 148 # full versions are inserted when the needed deltas
147 149 # become comparable to the uncompressed text
148 if not n or (end + len(data) - start) > len(text) * 2:
150 if not n or dist > len(text) * 2:
149 151 data = compress(text)
150 152 base = n
151 153 else:
General Comments 0
You need to be logged in to leave comments. Login now