Add support for rebasing a change

Change-Id: I1024341a00becdf317fb4f570696695ecdc92abf
This commit is contained in:
James E. Blair 2014-08-31 10:52:41 -07:00
parent add140034e
commit d714284593
4 changed files with 48 additions and 1 deletions

View File

@ -605,6 +605,9 @@ class DatabaseSession(object):
def getPendingTopics(self):
return self.session().query(Change).filter_by(pending_topic=True).all()
def getPendingRebases(self):
return self.session().query(Change).filter_by(pending_rebase=True).all()
def getAccountByID(self, id, name=None, username=None, email=None):
try:
account = self.session().query(Account).filter_by(id=id).one()

View File

@ -45,6 +45,7 @@ SEARCH_RESULTS = 'search results'
NEXT_CHANGE = 'next change'
PREV_CHANGE = 'previous change'
TOGGLE_HIDDEN_COMMENTS = 'toggle hidden comments'
REBASE_CHANGE = 'rebase change'
REFRESH = 'refresh'
EDIT_TOPIC = 'edit topic'
# Project list screen:
@ -83,6 +84,7 @@ DEFAULT_KEYMAP = {
NEXT_CHANGE: 'n',
PREV_CHANGE: 'p',
TOGGLE_HIDDEN_COMMENTS: 't',
REBASE_CHANGE: 'ctrl b',
REFRESH: 'ctrl r',
EDIT_TOPIC: 'ctrl t',

View File

@ -533,6 +533,8 @@ class UploadReviewsTask(Task):
with app.db.getSession() as session:
for c in session.getPendingTopics():
sync.submitTask(SetTopicTask(c.key, self.priority))
for c in session.getPendingRebases():
sync.submitTask(RebaseChangeTask(c.key, self.priority))
for m in session.getPendingMessages():
sync.submitTask(UploadReviewTask(m.key, self.priority))
@ -555,6 +557,23 @@ class SetTopicTask(Task):
data)
sync.submitTask(SyncChangeTask(change.id, priority=self.priority))
class RebaseChangeTask(Task):
def __init__(self, change_key, priority=NORMAL_PRIORITY):
super(RebaseChangeTask, self).__init__(priority)
self.change_key = change_key
def __repr__(self):
return '<RebaseChangeTask %s>' % (self.change_key,)
def run(self, sync):
app = sync.app
with app.db.getSession() as session:
change = session.getChange(self.change_key)
change.pending_rebase = False
# Inside db session for rollback
sync.post('changes/%s/rebase' % (change.id,), {})
sync.submitTask(SyncChangeTask(change.id, priority=self.priority))
class UploadReviewTask(Task):
def __init__(self, message_key, priority=NORMAL_PRIORITY):
super(UploadReviewTask, self).__init__(priority)

View File

@ -29,7 +29,7 @@ class EditTopicDialog(mywid.ButtonDialog):
signals = ['save', 'cancel']
def __init__(self, app, topic):
self.app = app
save_button = mywid.FixedButton('Search')
save_button = mywid.FixedButton('Save')
cancel_button = mywid.FixedButton('Cancel')
urwid.connect_signal(save_button, 'click',
lambda button:self._emit('save'))
@ -345,6 +345,8 @@ class ChangeView(urwid.WidgetWrap):
"Toggle the reviewed flag for the current change"),
(key(keymap.CHERRY_PICK),
"Cherry-pick the most recent revision onto the local repo"),
(key(keymap.REBASE_CHANGE),
"Rebase this change (remotely)"),
(key(keymap.REFRESH),
"Refresh this change"),
(key(keymap.EDIT_TOPIC),
@ -715,6 +717,9 @@ class ChangeView(urwid.WidgetWrap):
self.hide_comments = not self.hide_comments
self.refresh()
return None
if keymap.REBASE_CHANGE in commands:
self.rebaseChange()
return None
if keymap.REFRESH in commands:
self.app.sync.submitTask(
sync.SyncChangeTask(self.change_rest_id, priority=sync.HIGH_PRIORITY))
@ -735,6 +740,24 @@ class ChangeView(urwid.WidgetWrap):
screen = view_side_diff.SideDiffView(self.app, revision_key)
self.app.changeScreen(screen)
def rebaseChange(self):
dialog = mywid.YesNoDialog(u'Rebase Change',
u'Perform a remote rebase of this change?')
urwid.connect_signal(dialog, 'no', self.app.backScreen)
urwid.connect_signal(dialog, 'yes', self.doRebaseChange)
self.app.popup(dialog)
def doRebaseChange(self, button=None):
change_key = None
with self.app.db.getSession() as session:
change = session.getChange(self.change_key)
change.pending_rebase = True
change_key = change.key
self.app.sync.submitTask(
sync.RebaseChangeTask(change_key, sync.HIGH_PRIORITY))
self.app.backScreen()
self.refresh()
def editTopic(self):
dialog = EditTopicDialog(self.app, self.topic)
urwid.connect_signal(dialog, 'save',