comparison mercurial/mdiff.py @ 17940:c84ef0047a94

diff: unify calls to diffline diffline was called from trydiff for binary diffs and from unidiff for text diffs. In this patch we unify those calls into one. diffline is also a header, not part of diff mechanisms, so it makes sense to remove that responsibility from the mdiff module. In upcoming patches we will move diffline to patch module and keep grouping responsibilities.
author Guillermo P?rez <bisho@fb.com>
date Thu, 15 Nov 2012 12:16:08 -0800
parents d587925680d9
children 9a6e4d5d7ea8
comparison
equal deleted inserted replaced
17939:d587925680d9 17940:c84ef0047a94
154 parts.append('b/%s' % b) 154 parts.append('b/%s' % b)
155 else: 155 else:
156 parts.append(a) 156 parts.append(a)
157 return ' '.join(parts) + '\n' 157 return ' '.join(parts) + '\n'
158 158
159 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): 159 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
160 def datetag(date, fn=None): 160 def datetag(date, fn=None):
161 if not opts.git and not opts.nodates: 161 if not opts.git and not opts.nodates:
162 return '\t%s\n' % date 162 return '\t%s\n' % date
163 if fn and ' ' in fn: 163 if fn and ' ' in fn:
164 return '\t\n' 164 return '\t\n'
204 l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd, fn2))) 204 l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd, fn2)))
205 205
206 for ln in xrange(len(l)): 206 for ln in xrange(len(l)):
207 if l[ln][-1] != '\n': 207 if l[ln][-1] != '\n':
208 l[ln] += "\n\ No newline at end of file\n" 208 l[ln] += "\n\ No newline at end of file\n"
209
210 if r:
211 l.insert(0, diffline(r, fn1, fn2, opts))
212 209
213 return "".join(l) 210 return "".join(l)
214 211
215 # creates a headerless unified diff 212 # creates a headerless unified diff
216 # t1 and t2 are the text to be diffed 213 # t1 and t2 are the text to be diffed