Merge "Fix displaying new files"
This commit is contained in:
commit
283f60d046
|
@ -12,6 +12,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
import difflib
|
import difflib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -32,6 +33,7 @@ class GitCheckoutError(Exception):
|
||||||
|
|
||||||
class Repo(object):
|
class Repo(object):
|
||||||
def __init__(self, url, path):
|
def __init__(self, url, path):
|
||||||
|
self.log = logging.getLogger('gertty.gitrepo')
|
||||||
self.url = url
|
self.url = url
|
||||||
self.path = path
|
self.path = path
|
||||||
self.differ = difflib.Differ()
|
self.differ = difflib.Differ()
|
||||||
|
@ -135,7 +137,7 @@ class Repo(object):
|
||||||
oldc = repo.commit(old)
|
oldc = repo.commit(old)
|
||||||
newc = repo.commit(new)
|
newc = repo.commit(new)
|
||||||
files = []
|
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()
|
f = DiffFile()
|
||||||
files.append(f)
|
files.append(f)
|
||||||
old_lineno = 0
|
old_lineno = 0
|
||||||
|
@ -143,12 +145,18 @@ class Repo(object):
|
||||||
offset = 0
|
offset = 0
|
||||||
oldchunk = []
|
oldchunk = []
|
||||||
newchunk = []
|
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('---'):
|
if line.startswith('---'):
|
||||||
f.oldname = line[6:]
|
f.oldname = line[6:]
|
||||||
|
if line[4:] == '/dev/null':
|
||||||
|
f.oldname = 'Empty file'
|
||||||
continue
|
continue
|
||||||
if line.startswith('+++'):
|
if line.startswith('+++'):
|
||||||
f.newname = line[6:]
|
f.newname = line[6:]
|
||||||
|
if line[4:] == '/dev/null':
|
||||||
|
f.newname = 'Empty file'
|
||||||
continue
|
continue
|
||||||
if line.startswith('@@'):
|
if line.startswith('@@'):
|
||||||
#socket.sendall(line)
|
#socket.sendall(line)
|
||||||
|
@ -163,10 +171,12 @@ class Repo(object):
|
||||||
rest = line[1:]
|
rest = line[1:]
|
||||||
if key == '-':
|
if key == '-':
|
||||||
oldchunk.append(rest)
|
oldchunk.append(rest)
|
||||||
continue
|
if not last_line:
|
||||||
|
continue
|
||||||
if key == '+':
|
if key == '+':
|
||||||
newchunk.append(rest)
|
newchunk.append(rest)
|
||||||
continue
|
if not last_line:
|
||||||
|
continue
|
||||||
# end of chunk
|
# end of chunk
|
||||||
if oldchunk or newchunk:
|
if oldchunk or newchunk:
|
||||||
oldchunk, newchunk = self.intraline_diff(oldchunk, newchunk)
|
oldchunk, newchunk = self.intraline_diff(oldchunk, newchunk)
|
||||||
|
@ -192,5 +202,6 @@ class Repo(object):
|
||||||
old_lineno += 1
|
old_lineno += 1
|
||||||
new_lineno += 1
|
new_lineno += 1
|
||||||
continue
|
continue
|
||||||
raise Exception("Unhandled line: %s" % line)
|
if not last_line:
|
||||||
|
raise Exception("Unhandled line: %s" % line)
|
||||||
return files
|
return files
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ class DiffView(urwid.WidgetWrap):
|
||||||
|
|
||||||
def __init__(self, app, new_revision_key):
|
def __init__(self, app, new_revision_key):
|
||||||
super(DiffView, self).__init__(urwid.Pile([]))
|
super(DiffView, self).__init__(urwid.Pile([]))
|
||||||
|
self.log = logging.getLogger('gertty.view.diff')
|
||||||
self.app = app
|
self.app = app
|
||||||
self.new_revision_key = new_revision_key
|
self.new_revision_key = new_revision_key
|
||||||
with self.app.db.getSession() as session:
|
with self.app.db.getSession() as session:
|
||||||
|
|
Loading…
Reference in New Issue