Mercurial > public > mercurial-scm > hg
comparison mercurial/mdiff.py @ 5482:e5eedd74e70f
Use both the from and to name in mdiff.unidiff.
This fixes a compatibility issue with git diffs.
* * *
author | Dustin Sallings <dustin@spy.net> |
---|---|
date | Thu, 01 Nov 2007 12:17:59 -0700 |
parents | 7530334bf301 |
children | 3d1f9dcecdea |
comparison
equal
deleted
inserted
replaced
5481:003d1f174fe1 | 5482:e5eedd74e70f |
---|---|
57 text = re.sub('[ \t]+\n', '\n', text) | 57 text = re.sub('[ \t]+\n', '\n', text) |
58 if opts.ignoreblanklines: | 58 if opts.ignoreblanklines: |
59 text = re.sub('\n+', '', text) | 59 text = re.sub('\n+', '', text) |
60 return text | 60 return text |
61 | 61 |
62 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts): | 62 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): |
63 def datetag(date, addtab=True): | 63 def datetag(date, addtab=True): |
64 if not opts.git and not opts.nodates: | 64 if not opts.git and not opts.nodates: |
65 return '\t%s\n' % date | 65 return '\t%s\n' % date |
66 if addtab and ' ' in fn: | 66 if addtab and ' ' in fn1: |
67 return '\t\n' | 67 return '\t\n' |
68 return '\n' | 68 return '\n' |
69 | 69 |
70 if not a and not b: return "" | 70 if not a and not b: return "" |
71 epoch = util.datestr((0, 0)) | 71 epoch = util.datestr((0, 0)) |
74 def h(v): | 74 def h(v): |
75 # md5 is used instead of sha1 because md5 is supposedly faster | 75 # md5 is used instead of sha1 because md5 is supposedly faster |
76 return md5.new(v).digest() | 76 return md5.new(v).digest() |
77 if a and b and len(a) == len(b) and h(a) == h(b): | 77 if a and b and len(a) == len(b) and h(a) == h(b): |
78 return "" | 78 return "" |
79 l = ['Binary file %s has changed\n' % fn] | 79 l = ['Binary file %s has changed\n' % fn1] |
80 elif not a: | 80 elif not a: |
81 b = splitnewlines(b) | 81 b = splitnewlines(b) |
82 if a is None: | 82 if a is None: |
83 l1 = '--- /dev/null%s' % datetag(epoch, False) | 83 l1 = '--- /dev/null%s' % datetag(epoch, False) |
84 else: | 84 else: |
85 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) | 85 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) |
86 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) | 86 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) |
87 l3 = "@@ -0,0 +1,%d @@\n" % len(b) | 87 l3 = "@@ -0,0 +1,%d @@\n" % len(b) |
88 l = [l1, l2, l3] + ["+" + e for e in b] | 88 l = [l1, l2, l3] + ["+" + e for e in b] |
89 elif not b: | 89 elif not b: |
90 a = splitnewlines(a) | 90 a = splitnewlines(a) |
91 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) | 91 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) |
92 if b is None: | 92 if b is None: |
93 l2 = '+++ /dev/null%s' % datetag(epoch, False) | 93 l2 = '+++ /dev/null%s' % datetag(epoch, False) |
94 else: | 94 else: |
95 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) | 95 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) |
96 l3 = "@@ -1,%d +0,0 @@\n" % len(a) | 96 l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
97 l = [l1, l2, l3] + ["-" + e for e in a] | 97 l = [l1, l2, l3] + ["-" + e for e in a] |
98 else: | 98 else: |
99 al = splitnewlines(a) | 99 al = splitnewlines(a) |
100 bl = splitnewlines(b) | 100 bl = splitnewlines(b) |
101 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, opts=opts)) | 101 l = list(bunidiff(a, b, al, bl, "a/" + fn1, "b/" + fn2, opts=opts)) |
102 if not l: return "" | 102 if not l: return "" |
103 # difflib uses a space, rather than a tab | 103 # difflib uses a space, rather than a tab |
104 l[0] = "%s%s" % (l[0][:-2], datetag(ad)) | 104 l[0] = "%s%s" % (l[0][:-2], datetag(ad)) |
105 l[1] = "%s%s" % (l[1][:-2], datetag(bd)) | 105 l[1] = "%s%s" % (l[1][:-2], datetag(bd)) |
106 | 106 |
108 if l[ln][-1] != '\n': | 108 if l[ln][-1] != '\n': |
109 l[ln] += "\n\ No newline at end of file\n" | 109 l[ln] += "\n\ No newline at end of file\n" |
110 | 110 |
111 if r: | 111 if r: |
112 l.insert(0, "diff %s %s\n" % | 112 l.insert(0, "diff %s %s\n" % |
113 (' '.join(["-r %s" % rev for rev in r]), fn)) | 113 (' '.join(["-r %s" % rev for rev in r]), fn1)) |
114 | 114 |
115 return "".join(l) | 115 return "".join(l) |
116 | 116 |
117 # somewhat self contained replacement for difflib.unified_diff | 117 # somewhat self contained replacement for difflib.unified_diff |
118 # t1 and t2 are the text to be diffed | 118 # t1 and t2 are the text to be diffed |