Fix crash on comments from undisplayed files
If there is a comment on a file that would not otherwise be displayed because there is no diff, create an all-context diff for that file so the comment may be displayed. Also, update the number of comment lines to be displayed in the context expansion button ("Expand X lines of context"). Change-Id: I6db509b42032b282dbbfdbee0d639f97b8b70da3
This commit is contained in:
parent
4c2d2e8c6d
commit
473088474c
@ -431,3 +431,17 @@ class Repo(object):
|
|||||||
raise Exception("Unhandled line: %s" % line)
|
raise Exception("Unhandled line: %s" % line)
|
||||||
f.finalize()
|
f.finalize()
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
def getFile(self, old, new, path):
|
||||||
|
f = DiffFile()
|
||||||
|
f.oldname = path
|
||||||
|
f.newname = path
|
||||||
|
f.old_lineno = 1
|
||||||
|
f.new_lineno = 1
|
||||||
|
repo = git.Repo(self.path)
|
||||||
|
newc = repo.commit(new)
|
||||||
|
blob = newc.tree[path]
|
||||||
|
for line in blob.data_stream.read().splitlines():
|
||||||
|
f.addContextLine(line)
|
||||||
|
f.finalize()
|
||||||
|
return f
|
||||||
|
@ -186,11 +186,11 @@ class DiffContextButton(urwid.WidgetWrap):
|
|||||||
focus_map={'context-button':'focused-context-button'}
|
focus_map={'context-button':'focused-context-button'}
|
||||||
buttons = [mywid.FixedButton(('context-button', "Expand previous 10"),
|
buttons = [mywid.FixedButton(('context-button', "Expand previous 10"),
|
||||||
on_press=self.prev),
|
on_press=self.prev),
|
||||||
mywid.FixedButton(('context-button',
|
mywid.FixedButton(('context-button', "Expand"),
|
||||||
"Expand %s lines of context" % len(chunk.lines)),
|
|
||||||
on_press=self.all),
|
on_press=self.all),
|
||||||
mywid.FixedButton(('context-button', "Expand next 10"),
|
mywid.FixedButton(('context-button', "Expand next 10"),
|
||||||
on_press=self.next)]
|
on_press=self.next)]
|
||||||
|
self._buttons = buttons
|
||||||
buttons = [('pack', urwid.AttrMap(b, None, focus_map=focus_map)) for b in buttons]
|
buttons = [('pack', urwid.AttrMap(b, None, focus_map=focus_map)) for b in buttons]
|
||||||
buttons = urwid.Columns([urwid.Text('')] + buttons + [urwid.Text('')],
|
buttons = urwid.Columns([urwid.Text('')] + buttons + [urwid.Text('')],
|
||||||
dividechars=4)
|
dividechars=4)
|
||||||
@ -199,6 +199,11 @@ class DiffContextButton(urwid.WidgetWrap):
|
|||||||
self.view = view
|
self.view = view
|
||||||
self.diff = diff
|
self.diff = diff
|
||||||
self.chunk = chunk
|
self.chunk = chunk
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self._buttons[1].set_label("Expand %s lines of context" %
|
||||||
|
(len(self.chunk.lines)),)
|
||||||
|
|
||||||
def prev(self, button):
|
def prev(self, button):
|
||||||
self.view.expandChunk(self.diff, self.chunk, from_start=10)
|
self.view.expandChunk(self.diff, self.chunk, from_start=10)
|
||||||
@ -253,6 +258,7 @@ class DiffView(urwid.WidgetWrap):
|
|||||||
self.project_name = new_revision.change.project.name
|
self.project_name = new_revision.change.project.name
|
||||||
self.commit = new_revision.commit
|
self.commit = new_revision.commit
|
||||||
comment_lists = {}
|
comment_lists = {}
|
||||||
|
comment_filenames = set()
|
||||||
for comment in new_revision.comments:
|
for comment in new_revision.comments:
|
||||||
if comment.parent:
|
if comment.parent:
|
||||||
if old_revision: # we're not looking at the base
|
if old_revision: # we're not looking at the base
|
||||||
@ -272,6 +278,7 @@ class DiffView(urwid.WidgetWrap):
|
|||||||
('comment', u': '+comment.message)]
|
('comment', u': '+comment.message)]
|
||||||
comment_list.append((comment.key, message))
|
comment_list.append((comment.key, message))
|
||||||
comment_lists[key] = comment_list
|
comment_lists[key] = comment_list
|
||||||
|
comment_filenames.add(comment.file)
|
||||||
for comment in old_comments:
|
for comment in old_comments:
|
||||||
if comment.parent:
|
if comment.parent:
|
||||||
continue
|
continue
|
||||||
@ -288,14 +295,25 @@ class DiffView(urwid.WidgetWrap):
|
|||||||
('comment', u': '+comment.message)]
|
('comment', u': '+comment.message)]
|
||||||
comment_list.append((comment.key, message))
|
comment_list.append((comment.key, message))
|
||||||
comment_lists[key] = comment_list
|
comment_lists[key] = comment_list
|
||||||
|
comment_filenames.add(comment.file)
|
||||||
repo = self.app.getRepo(self.project_name)
|
repo = self.app.getRepo(self.project_name)
|
||||||
self._w.contents.append((self.app.header, ('pack', 1)))
|
self._w.contents.append((self.app.header, ('pack', 1)))
|
||||||
self._w.contents.append((urwid.Divider(), ('pack', 1)))
|
self._w.contents.append((urwid.Divider(), ('pack', 1)))
|
||||||
lines = [] # The initial set of lines to display
|
lines = [] # The initial set of lines to display
|
||||||
self.file_diffs = [{}, {}] # Mapping of fn -> DiffFile object (old, new)
|
self.file_diffs = [{}, {}] # Mapping of fn -> DiffFile object (old, new)
|
||||||
# this is a list of files:
|
# this is a list of files:
|
||||||
for i, diff in enumerate(repo.diff(self.base_commit, self.commit,
|
diffs = repo.diff(self.base_commit, self.commit,
|
||||||
show_old_commit=show_old_commit)):
|
show_old_commit=show_old_commit)
|
||||||
|
for diff in diffs:
|
||||||
|
comment_filenames.discard(diff.oldname)
|
||||||
|
comment_filenames.discard(diff.newname)
|
||||||
|
# There are comments referring to these files which do not
|
||||||
|
# appear in the diff so we should create fake diff objects
|
||||||
|
# that contain the full text.
|
||||||
|
for filename in comment_filenames:
|
||||||
|
diff = repo.getFile(self.base_commit, self.commit, filename)
|
||||||
|
diffs.append(diff)
|
||||||
|
for i, diff in enumerate(diffs):
|
||||||
if i > 0:
|
if i > 0:
|
||||||
lines.append(urwid.Text(''))
|
lines.append(urwid.Text(''))
|
||||||
self.file_diffs[gitrepo.OLD][diff.oldname] = diff
|
self.file_diffs[gitrepo.OLD][diff.oldname] = diff
|
||||||
@ -382,6 +400,8 @@ class DiffView(urwid.WidgetWrap):
|
|||||||
chunk.calcRange()
|
chunk.calcRange()
|
||||||
if not chunk.lines:
|
if not chunk.lines:
|
||||||
self.listbox.body.remove(chunk.button)
|
self.listbox.body.remove(chunk.button)
|
||||||
|
else:
|
||||||
|
chunk.button.update()
|
||||||
|
|
||||||
def makeLines(self, diff, lines_to_add, comment_lists):
|
def makeLines(self, diff, lines_to_add, comment_lists):
|
||||||
lines = []
|
lines = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user