Fix diff display of deleted empty files

This case was not handled at all and caused a crash.

Also handle the case where a file present in the diff is not
present in the new commit while diffing between patchsets.

Change-Id: I24b54b6db7eae8d6c6c349ab6ed2bf846f104f86
This commit is contained in:
James E. Blair 2015-05-06 06:43:06 -07:00
parent 3c9124969b
commit 890a0892ef
3 changed files with 10 additions and 6 deletions

View File

@ -480,8 +480,10 @@ class Repo(object):
# There is no diff, possibly because this is simply a
# rename. Include context lines so that comments may
# appear.
newc = repo.commit(new)
blob = newc.tree[f.newname]
if not f.new_empty:
blob = newc.tree[f.newname]
else:
blob = oldc.tree[f.oldname]
f.old_lineno = 1
f.new_lineno = 1
for line in blob.data_stream.read().splitlines():

View File

@ -377,7 +377,7 @@ class BaseDiffView(urwid.WidgetWrap):
elif diff.newname in self.old_file_keys:
old_key = self.old_file_keys[diff.newname]
if not diff.new_empty:
new_key = self.new_file_keys[diff.newname]
new_key = self.new_file_keys.get(diff.newname)
return LineContext(
old_key, new_key,
diff.oldname, diff.newname,

View File

@ -31,16 +31,18 @@ class SideDiffCommentEdit(BaseDiffCommentEdit):
self.old = urwid.Edit(edit_text=old, multiline=True)
self.new = urwid.Edit(edit_text=new, multiline=True)
self.contents.append((urwid.Text(u''), ('given', LN_COL_WIDTH, False)))
if context.old_ln is not None or context.header:
if context.old_file_key and (context.old_ln is not None or context.header):
self.contents.append((urwid.AttrMap(self.old, 'draft-comment'), ('weight', 1, False)))
else:
self.contents.append((urwid.Text(u''), ('weight', 1, False)))
self.contents.append((urwid.Text(u''), ('given', LN_COL_WIDTH, False)))
if context.new_ln is not None or context.header:
if context.new_file_key and (context.new_ln is not None or context.header):
self.contents.append((urwid.AttrMap(self.new, 'draft-comment'), ('weight', 1, False)))
new_editable = True
else:
self.contents.append((urwid.Text(u''), ('weight', 1, False)))
if context.new_ln is not None or context.header:
new_editable = False
if new_editable:
self.focus_position = 3
else:
self.focus_position = 1