Process more diff output

This gets up to 10,000 lines of diff context information, but does
not display it.  Now we have the data and in a future change can
display more context if needed in order to show comments or if the
user requests it.

Change-Id: Id569732ffa40610f67bf479de8bf936580fbacf1
This commit is contained in:
James E. Blair 2014-05-03 17:42:37 -07:00
parent a44a82bff3
commit 067aa68dcd
2 changed files with 64 additions and 44 deletions

View File

@ -19,17 +19,18 @@ import re
import git
class DiffContextChunk(object):
context = True
class DiffChunk(object):
def __init__(self):
self.oldlines = []
self.newlines = []
self.first = False
self.last = False
class DiffChangedChunk(object):
class DiffContextChunk(DiffChunk):
context = True
class DiffChangedChunk(DiffChunk):
context = False
def __init__(self):
self.oldlines = []
self.newlines = []
class DiffFile(object):
def __init__(self):
@ -46,6 +47,11 @@ class DiffFile(object):
return
self.current_chunk.lines = zip(self.current_chunk.oldlines,
self.current_chunk.newlines)
if not self.chunks:
self.current_chunk.first = True
else:
self.chunks[-1].last = False
self.current_chunk.last = True
self.chunks.append(self.current_chunk)
self.current_chunk = None
@ -194,7 +200,7 @@ class Repo(object):
return output_old, output_new
header_re = re.compile('@@ -(\d+)(,\d+)? \+(\d+)(,\d+)? @@')
def diff(self, old, new, context=20):
def diff(self, old, new, context=10000):
repo = git.Repo(self.path)
#'-y', '-x', 'diff -C10', old, new, path).split('\n'):
oldc = repo.commit(old)

View File

@ -155,43 +155,16 @@ This Screen
urwid.Text(diff.oldname),
urwid.Text(diff.newname)]))
for chunk in diff.chunks:
for old, new in chunk.lines:
context = LineContext(
None, self.new_revision_key,
None, self.new_revision_num,
diff.oldname, diff.newname,
old[0], new[0])
lines.append(DiffLine(self.app, context, old, new,
callback=self.onSelect))
# see if there are any comments for this line
key = 'old-%s-%s' % (old[0], diff.oldname)
old_list = comment_lists.get(key, [])
key = 'new-%s-%s' % (new[0], diff.newname)
new_list = comment_lists.get(key, [])
while old_list or new_list:
old_comment_key = new_comment_key = None
old_comment = new_comment = u''
if old_list:
(old_comment_key, old_comment) = old_list.pop(0)
if new_list:
(new_comment_key, new_comment) = new_list.pop(0)
lines.append(DiffComment(context, old_comment, new_comment))
# see if there are any draft comments for this line
key = 'olddraft-%s-%s' % (old[0], diff.oldname)
old_list = comment_lists.get(key, [])
key = 'newdraft-%s-%s' % (old[0], diff.oldname)
new_list = comment_lists.get(key, [])
while old_list or new_list:
old_comment_key = new_comment_key = None
old_comment = new_comment = u''
if old_list:
(old_comment_key, old_comment) = old_list.pop(0)
if new_list:
(new_comment_key, new_comment) = new_list.pop(0)
lines.append(DiffCommentEdit(context,
old_comment_key,
new_comment_key,
old_comment, new_comment))
if chunk.context:
if not chunk.first:
lines += self.makeLines(diff, chunk.lines[:10], comment_lists)
lines.append(urwid.Text('...'))
if not chunk.last:
lines += self.makeLines(diff, chunk.lines[-10:], comment_lists)
else:
lines += self.makeLines(diff, chunk.lines, comment_lists)
if comment_lists:
self.log.debug("Undisplayed comments: %s" % comment_lists)
listwalker = urwid.SimpleFocusListWalker(lines)
self.listbox = urwid.ListBox(listwalker)
self._w.contents.append((self.listbox, ('weight', 1)))
@ -199,6 +172,47 @@ This Screen
self.draft_comments = []
self._w.set_focus(self.old_focus)
def makeLines(self, diff, lines_to_add, comment_lists):
lines = []
for old, new in lines_to_add:
context = LineContext(
None, self.new_revision_key,
None, self.new_revision_num,
diff.oldname, diff.newname,
old[0], new[0])
lines.append(DiffLine(self.app, context, old, new,
callback=self.onSelect))
# see if there are any comments for this line
key = 'old-%s-%s' % (old[0], diff.oldname)
old_list = comment_lists.pop(key, [])
key = 'new-%s-%s' % (new[0], diff.newname)
new_list = comment_lists.pop(key, [])
while old_list or new_list:
old_comment_key = new_comment_key = None
old_comment = new_comment = u''
if old_list:
(old_comment_key, old_comment) = old_list.pop(0)
if new_list:
(new_comment_key, new_comment) = new_list.pop(0)
lines.append(DiffComment(context, old_comment, new_comment))
# see if there are any draft comments for this line
key = 'olddraft-%s-%s' % (old[0], diff.oldname)
old_list = comment_lists.pop(key, [])
key = 'newdraft-%s-%s' % (old[0], diff.oldname)
new_list = comment_lists.pop(key, [])
while old_list or new_list:
old_comment_key = new_comment_key = None
old_comment = new_comment = u''
if old_list:
(old_comment_key, old_comment) = old_list.pop(0)
if new_list:
(new_comment_key, new_comment) = new_list.pop(0)
lines.append(DiffCommentEdit(context,
old_comment_key,
new_comment_key,
old_comment, new_comment))
return lines
def refresh(self):
#TODO
pass