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