Handle "No newline at end of file" and add --no-sync option
Change-Id: Ic40e4151eeacfd0514f5bdfb7eb268b0a08eb19b
This commit is contained in:
parent
f15feec7bf
commit
dfeef53895
@ -99,7 +99,7 @@ class StatusHeader(urwid.WidgetWrap):
|
||||
self.sync.set_text(u' Sync: %i' % self.app.sync.queue.qsize())
|
||||
|
||||
class App(object):
|
||||
def __init__(self, server=None, debug=False):
|
||||
def __init__(self, server=None, debug=False, disable_sync=False):
|
||||
self.server = server
|
||||
self.config = config.Config(server)
|
||||
if debug:
|
||||
@ -123,8 +123,11 @@ class App(object):
|
||||
unhandled_input=self.unhandledInput)
|
||||
sync_pipe = self.loop.watch_pipe(self.refresh)
|
||||
#self.loop.screen.set_terminal_properties(colors=88)
|
||||
self.sync_thread = threading.Thread(target=self.sync.run, args=(sync_pipe,))
|
||||
self.sync_thread.start()
|
||||
if not disable_sync:
|
||||
self.sync_thread = threading.Thread(target=self.sync.run, args=(sync_pipe,))
|
||||
self.sync_thread.start()
|
||||
else:
|
||||
self.sync_thread = None
|
||||
self.loop.run()
|
||||
|
||||
def changeScreen(self, widget):
|
||||
@ -183,7 +186,9 @@ if __name__ == '__main__':
|
||||
description='Console client for Gerrit Code Review.')
|
||||
parser.add_argument('-d', dest='debug', action='store_true',
|
||||
help='enable debug logging')
|
||||
parser.add_argument('--no-sync', dest='no_sync', action='store_true',
|
||||
help='disable remote syncing')
|
||||
parser.add_argument('server', nargs='?',
|
||||
help='the server to use (as specified in config file)')
|
||||
args = parser.parse_args()
|
||||
g = App(args.server, args.debug)
|
||||
g = App(args.server, args.debug, args.no_sync)
|
||||
|
@ -145,6 +145,7 @@ class Repo(object):
|
||||
offset = 0
|
||||
oldchunk = []
|
||||
newchunk = []
|
||||
prev_key = ''
|
||||
diff_lines = diff_context.diff.split('\n')
|
||||
for i, line in enumerate(diff_lines):
|
||||
last_line = (i == len(diff_lines)-1)
|
||||
@ -166,17 +167,37 @@ class Repo(object):
|
||||
new_lineno = int(m.group(3))
|
||||
continue
|
||||
if not line:
|
||||
line = ' '
|
||||
if prev_key != '\\':
|
||||
# Strangely, we get an extra newline in the
|
||||
# diff in the case that the last line is "\ No
|
||||
# newline at end of file". This is a
|
||||
# workaround for that.
|
||||
prev_key = ''
|
||||
line = 'X '
|
||||
else:
|
||||
line = ' '
|
||||
key = line[0]
|
||||
rest = line[1:]
|
||||
if key == '\\':
|
||||
# This is for "\ No newline at end of file" which
|
||||
# follows either a - or + line to indicate which
|
||||
# file it's talking about. For now, treat it like
|
||||
# normal text and let the user infer from context
|
||||
# that it's not actually in the file. Potential
|
||||
# TODO: highlight it to make that more clear.
|
||||
key = prev_key
|
||||
prev_key = '\\'
|
||||
if key == '-':
|
||||
prev_key = '-'
|
||||
oldchunk.append(rest)
|
||||
if not last_line:
|
||||
continue
|
||||
if key == '+':
|
||||
prev_key = '+'
|
||||
newchunk.append(rest)
|
||||
if not last_line:
|
||||
continue
|
||||
prev_key = ''
|
||||
# end of chunk
|
||||
if oldchunk or newchunk:
|
||||
oldchunk, newchunk = self.intraline_diff(oldchunk, newchunk)
|
||||
|
Loading…
x
Reference in New Issue
Block a user