comparison hgext/record.py @ 6949:834f7e069cae

record: take diff lines for lack of trailing newlines into account (issue1282) The record extension incorrectly re-calculated the size lines for unified diff hunks. It counted a '\\ No newline at end of file\n' line towards the number of lines of trailing context, while it's not actually part of the context (and certainly isn't added as a line to the resulting output). Use the local name of a variable that was access through the nonlocal scope while we're at it. Seeing the variable was a little bewildering.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sun, 31 Aug 2008 11:34:52 +0200
parents e75aab656f46
children 381a892159d9
comparison
equal deleted inserted replaced
6929:1b15d6e7cc3c 6949:834f7e069cae
153 self.hunk = hunk 153 self.hunk = hunk
154 self.added, self.removed = countchanges(self.hunk) 154 self.added, self.removed = countchanges(self.hunk)
155 155
156 def write(self, fp): 156 def write(self, fp):
157 delta = len(self.before) + len(self.after) 157 delta = len(self.before) + len(self.after)
158 if self.after and self.after[-1] == '\\ No newline at end of file\n':
159 delta -= 1
158 fromlen = delta + self.removed 160 fromlen = delta + self.removed
159 tolen = delta + self.added 161 tolen = delta + self.added
160 fp.write('@@ -%d,%d +%d,%d @@%s\n' % 162 fp.write('@@ -%d,%d +%d,%d @@%s\n' %
161 (self.fromline, fromlen, self.toline, tolen, 163 (self.fromline, fromlen, self.toline, tolen,
162 self.proc and (' ' + self.proc))) 164 self.proc and (' ' + self.proc)))
204 206
205 def addhunk(self, hunk): 207 def addhunk(self, hunk):
206 if self.context: 208 if self.context:
207 self.before = self.context 209 self.before = self.context
208 self.context = [] 210 self.context = []
209 self.hunk = data 211 self.hunk = hunk
210 212
211 def newfile(self, hdr): 213 def newfile(self, hdr):
212 self.addcontext([]) 214 self.addcontext([])
213 h = header(hdr) 215 h = header(hdr)
214 self.stream.append(h) 216 self.stream.append(h)