comparison mercurial/mdiff.py @ 7200:ca5ac40949dc

patch/diff: use a separate function to write the first line of a file diff
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 22 Oct 2008 13:14:52 +0200
parents 13fe85fe396b
children ad28279053ef
comparison
equal deleted inserted replaced
7199:dd891d0d97a3 7200:ca5ac40949dc
64 text = re.sub('[ \t]+\n', '\n', text) 64 text = re.sub('[ \t]+\n', '\n', text)
65 if opts.ignoreblanklines: 65 if opts.ignoreblanklines:
66 text = re.sub('\n+', '', text) 66 text = re.sub('\n+', '', text)
67 return text 67 return text
68 68
69 def diffline(revs, a, b, opts):
70 parts = ['diff']
71 if opts.git:
72 parts.append('--git')
73 if revs and not opts.git:
74 parts.append(' '.join(["-r %s" % rev for rev in revs]))
75 if opts.git:
76 parts.append('a/%s' % a)
77 parts.append('b/%s' % b)
78 else:
79 parts.append(a)
80 return ' '.join(parts) + '\n'
81
69 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): 82 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts):
70 def datetag(date, addtab=True): 83 def datetag(date, addtab=True):
71 if not opts.git and not opts.nodates: 84 if not opts.git and not opts.nodates:
72 return '\t%s\n' % date 85 return '\t%s\n' % date
73 if addtab and ' ' in fn1: 86 if addtab and ' ' in fn1:
111 for ln in xrange(len(l)): 124 for ln in xrange(len(l)):
112 if l[ln][-1] != '\n': 125 if l[ln][-1] != '\n':
113 l[ln] += "\n\ No newline at end of file\n" 126 l[ln] += "\n\ No newline at end of file\n"
114 127
115 if r: 128 if r:
116 l.insert(0, "diff %s %s\n" % 129 l.insert(0, diffline(r, fn1, fn2, opts))
117 (' '.join(["-r %s" % rev for rev in r]), fn1))
118 130
119 return "".join(l) 131 return "".join(l)
120 132
121 # somewhat self contained replacement for difflib.unified_diff 133 # somewhat self contained replacement for difflib.unified_diff
122 # t1 and t2 are the text to be diffed 134 # t1 and t2 are the text to be diffed