Browse Source

Fix displaying new files

Change-Id: Idacb212482b33574ba71bf8f90b62b594616b77a
Closes-Task: some subtask of story 70
changes/91/391991/1
James E. Blair 8 years ago
parent
commit
5585ba6786
  1. 21
      gertty/gitrepo.py
  2. 2
      gertty/view/diff.py

21
gertty/gitrepo.py

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import difflib
import os
import re
@ -32,6 +33,7 @@ class GitCheckoutError(Exception):
class Repo(object):
def __init__(self, url, path):
self.log = logging.getLogger('gertty.gitrepo')
self.url = url
self.path = path
self.differ = difflib.Differ()
@ -135,7 +137,7 @@ class Repo(object):
oldc = repo.commit(old)
newc = repo.commit(new)
files = []
for context in oldc.diff(newc, create_patch=True, U=context):
for diff_context in oldc.diff(newc, create_patch=True, U=context):
f = DiffFile()
files.append(f)
old_lineno = 0
@ -143,12 +145,18 @@ class Repo(object):
offset = 0
oldchunk = []
newchunk = []
for line in context.diff.split('\n'):
diff_lines = diff_context.diff.split('\n')
for i, line in enumerate(diff_lines):
last_line = (i == len(diff_lines)-1)
if line.startswith('---'):
f.oldname = line[6:]
if line[4:] == '/dev/null':
f.oldname = 'Empty file'
continue
if line.startswith('+++'):
f.newname = line[6:]
if line[4:] == '/dev/null':
f.newname = 'Empty file'
continue
if line.startswith('@@'):
#socket.sendall(line)
@ -163,10 +171,12 @@ class Repo(object):
rest = line[1:]
if key == '-':
oldchunk.append(rest)
continue
if not last_line:
continue
if key == '+':
newchunk.append(rest)
continue
if not last_line:
continue
# end of chunk
if oldchunk or newchunk:
oldchunk, newchunk = self.intraline_diff(oldchunk, newchunk)
@ -192,5 +202,6 @@ class Repo(object):
old_lineno += 1
new_lineno += 1
continue
raise Exception("Unhandled line: %s" % line)
if not last_line:
raise Exception("Unhandled line: %s" % line)
return files

2
gertty/view/diff.py

@ -13,6 +13,7 @@
# under the License.
import datetime
import logging
import urwid
@ -103,6 +104,7 @@ class DiffView(urwid.WidgetWrap):
def __init__(self, app, new_revision_key):
super(DiffView, self).__init__(urwid.Pile([]))
self.log = logging.getLogger('gertty.view.diff')
self.app = app
self.new_revision_key = new_revision_key
with self.app.db.getSession() as session:

Loading…
Cancel
Save