def checkGitRepo(self): missing_revisions = set() change_number = None change_id = None with self.app.db.getSession() as session: change = session.getChange(self.change_key) change_number = change.number change_id = change.id repo = self.app.getRepo(change.project.name) for revision in change.revisions: if not repo.hasCommit(revision.parent): missing_revisions.add(revision.parent) if not repo.hasCommit(revision.commit): missing_revisions.add(revision.commit) if missing_revisions: break if missing_revisions: if self.app.sync.offline: raise gertty.view.DisplayError( "Git commits not present in local repository") self.app.log.warning("Missing some commits for change %s %s", change_number, missing_revisions) task = sync.SyncChangeTask(change_id, force_fetch=True, priority=sync.HIGH_PRIORITY) self.app.sync.submitTask(task) succeeded = task.wait(300) if not succeeded: raise gertty.view.DisplayError( "Git commits not present in local repository")
def _syncOneChangeFromQuery(self, query): number = changeid = restid = None if query.startswith("change:"): number = query.split(':')[1].strip() try: number = int(number) except ValueError: number = None changeid = query.split(':')[1].strip() if not (number or changeid): return with self.db.getSession() as session: if number: changes = [session.getChangeByNumber(number)] elif changeid: changes = session.getChangesByChangeID(changeid) change_keys = [c.key for c in changes if c] restids = [c.id for c in changes if c] if not change_keys: if self.sync.offline: raise Exception('Can not sync change while offline.') dialog = mywid.SystemMessage("Syncing change...") self.popup(dialog, width=40, height=6) self.loop.draw_screen() try: task = sync.SyncChangeByNumberTask(number or changeid, sync.HIGH_PRIORITY) self.sync.submitTask(task) succeeded = task.wait(300) if not succeeded: raise Exception('Unable to find change.') for subtask in task.tasks: succeeded = subtask.wait(300) if not succeeded: raise Exception('Unable to sync change.') finally: # Remove "syncing..." popup self.backScreen() with self.db.getSession() as session: if number: changes = [session.getChangeByNumber(number)] elif changeid: changes = session.getChangesByChangeID(changeid) change_keys = [c.key for c in changes if c] elif restids: for restid in restids: task = sync.SyncChangeTask(restid, sync.HIGH_PRIORITY) self.sync.submitTask(task) if not change_keys: raise Exception('Change is not in local database.')
def keypress(self, size, key): r = super(ChangeView, self).keypress(size, key) commands = self.app.config.keymap.getCommands(r) if keymap.TOGGLE_REVIEWED in commands: self.toggleReviewed() self.refresh() return None if keymap.TOGGLE_HIDDEN in commands: self.toggleHidden() self.refresh() return None if keymap.REVIEW in commands: row = self.revision_rows[self.last_revision_key] row.review_button.openReview() return None if keymap.DIFF in commands: row = self.revision_rows[self.last_revision_key] row.diff(None) return None if keymap.LOCAL_CHECKOUT in commands: row = self.revision_rows[self.last_revision_key] row.checkout(None) return None if keymap.LOCAL_CHERRY_PICK in commands: row = self.revision_rows[self.last_revision_key] row.cherryPick(None) return None if keymap.SEARCH_RESULTS in commands: widget = self.app.findChangeList() if widget: self.app.backScreen(widget) return None if ((keymap.NEXT_CHANGE in commands) or (keymap.PREV_CHANGE in commands)): widget = self.app.findChangeList() if widget: if keymap.NEXT_CHANGE in commands: new_change_key = widget.getNextChangeKey(self.change_key) else: new_change_key = widget.getPrevChangeKey(self.change_key) if new_change_key: try: view = ChangeView(self.app, new_change_key) self.app.changeScreen(view, push=False) except gertty.view.DisplayError as e: self.app.error(e.message) return None if keymap.TOGGLE_HIDDEN_COMMENTS in commands: self.hide_comments = not self.hide_comments self.refresh() return None if keymap.ABANDON_CHANGE in commands: self.abandonChange() return None if keymap.EDIT_COMMIT_MESSAGE in commands: self.editCommitMessage() return None if keymap.REBASE_CHANGE in commands: self.rebaseChange() return None if keymap.RESTORE_CHANGE in commands: self.restoreChange() return None if keymap.REFRESH in commands: self.app.sync.submitTask( sync.SyncChangeTask(self.change_rest_id, priority=sync.HIGH_PRIORITY)) self.app.status.update() return None if keymap.EDIT_TOPIC in commands: self.editTopic() return None if keymap.CHERRY_PICK_CHANGE in commands: self.cherryPickChange() return None if r in self.app.config.reviewkeys: self.reviewKey(self.app.config.reviewkeys[r]) return None return r