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.
--- a/hgext/record.py Thu Aug 21 19:02:56 2008 +0200
+++ b/hgext/record.py Sun Aug 31 11:34:52 2008 +0200
@@ -155,6 +155,8 @@
def write(self, fp):
delta = len(self.before) + len(self.after)
+ if self.after and self.after[-1] == '\\ No newline at end of file\n':
+ delta -= 1
fromlen = delta + self.removed
tolen = delta + self.added
fp.write('@@ -%d,%d +%d,%d @@%s\n' %
@@ -206,7 +208,7 @@
if self.context:
self.before = self.context
self.context = []
- self.hunk = data
+ self.hunk = hunk
def newfile(self, hdr):
self.addcontext([])