예제 #1
0
파일: app.py 프로젝트: hubtty/hubtty
 def localCherryPickCommit(self, repository_name, commit_sha):
     repo = gitrepo.get_repo(repository_name, self.config)
     try:
         repo.cherryPick(commit_sha)
         dialog = mywid.MessageDialog('Cherry-Pick', 'Pull request cherry-picked in %s' % repo.path)
         min_height=8
     except gitrepo.GitCheckoutError as e:
         dialog = mywid.MessageDialog('Error', e.msg)
         min_height=12
     urwid.connect_signal(dialog, 'close',
         lambda button: self.backScreen())
     self.popup(dialog, min_height=min_height)
예제 #2
0
파일: app.py 프로젝트: weshayutin/hubtty
 def localCheckoutCommit(self, project_name, commit_sha):
     repo = gitrepo.get_repo(project_name, self.config)
     try:
         repo.checkout(commit_sha)
         dialog = mywid.MessageDialog(
             'Checkout', 'Change checked out in %s' % repo.path)
         min_height = 8
     except gitrepo.GitCheckoutError as e:
         dialog = mywid.MessageDialog('Error', e.msg)
         min_height = 12
     urwid.connect_signal(dialog, 'close', lambda button: self.backScreen())
     self.popup(dialog, min_height=min_height)
예제 #3
0
 def _init(self):
     del self._w.contents[:]
     self.searchInit()
     with self.app.db.getSession() as session:
         new_commit = session.getCommit(self.new_commit_key)
         old_comments = []
         new_comments = []
         self.old_file_keys = {}
         self.new_file_keys = {}
         if self.old_commit_key is not None:
             old_commit = session.getCommit(self.old_commit_key)
             self.base_sha = old_commit.sha
             for f in old_commit.files:
                 old_comments += f.comments
                 self.old_file_keys[f.path] = f.key
             show_old_commit = True
         else:
             old_commit = None
             self.base_sha = new_commit.parent
             show_old_commit = False
             # The old files are the same as the new files since we
             # are diffing from base -> change, however, we should
             # use the old file names for file lookup.
             for f in new_commit.files:
                 if f.old_path:
                     self.old_file_keys[f.old_path] = f.key
                 else:
                     self.old_file_keys[f.path] = f.key
         self.title = u'Diff of %s from %s to %s' % (
             new_commit.pull_request.repository.name,
             new_commit.parent[0:7], new_commit.sha[0:7])
         self.short_title = u'Diff of %s' % (new_commit.sha[0:7], )
         self.pr_key = new_commit.pull_request.key
         self.repository_name = new_commit.pull_request.repository.name
         self.sha = new_commit.sha
         for f in new_commit.files:
             new_comments += f.current_comments
             self.new_file_keys[f.path] = f.key
         comment_lists = {}
         comment_filenames = set()
         for comment in new_comments:
             path = comment.file.path
             if comment.parent:
                 if old_commit:  # we're not looking at the base
                     continue
                 key = 'old'
                 if comment.file.old_path:
                     path = comment.file.old_path
             else:
                 key = 'new'
             if comment.draft:
                 key += 'draft'
             key += '-' + str(comment.line)
             key += '-' + path
             comment_list = comment_lists.get(key, [])
             if comment.draft:
                 message = comment.message
             else:
                 message = [('comment-name', comment.author.name
                             or comment.author.username),
                            ('comment', u': ' + comment.message)]
             comment_list.append((comment.key, message))
             comment_lists[key] = comment_list
             comment_filenames.add(path)
         for comment in old_comments:
             if comment.parent:
                 continue
             path = comment.file.path
             key = 'old'
             if comment.draft:
                 key += 'draft'
             key += '-' + str(comment.line)
             key += '-' + path
             comment_list = comment_lists.get(key, [])
             if comment.draft:
                 message = comment.message
             else:
                 message = [('comment-name', comment.author.name
                             or comment.author.username),
                            ('comment', u': ' + comment.message)]
             comment_list.append((comment.key, message))
             comment_lists[key] = comment_list
             comment_filenames.add(path)
     repo = gitrepo.get_repo(self.repository_name, self.app.config)
     self._w.contents.append((self.app.header, ('pack', 1)))
     self.file_reminder = self.makeFileReminder()
     self._w.contents.append((self.file_reminder, ('pack', 1)))
     lines = []  # The initial set of lines to display
     self.file_diffs = [{},
                        {}]  # Mapping of fn -> DiffFile object (old, new)
     # this is a list of files:
     diffs = repo.diff(self.base_sha,
                       self.sha,
                       show_old_commit=show_old_commit)
     for diff in diffs:
         comment_filenames.discard(diff.oldname)
         comment_filenames.discard(diff.newname)
     # There are comments referring to these files which do not
     # appear in the diff so we should create fake diff objects
     # that contain the full text.
     for filename in comment_filenames:
         diff = repo.getFile(self.base_sha, self.sha, filename)
         if diff:
             diffs.append(diff)
         else:
             self.log.debug("Unable to find file %s in commit %s" %
                            (filename, self.sha))
     for i, diff in enumerate(diffs):
         if i > 0:
             lines.append(urwid.Text(''))
         self.file_diffs[gitrepo.OLD][diff.oldname] = diff
         self.file_diffs[gitrepo.NEW][diff.newname] = diff
         lines.extend(self.makeFileHeader(diff, comment_lists))
         for chunk in diff.chunks:
             if chunk.context:
                 if not chunk.first:
                     lines += self.makeLines(diff, chunk.lines[:10],
                                             comment_lists)
                     del chunk.lines[:10]
                 button = DiffContextButton(self, diff, chunk)
                 chunk.button = button
                 lines.append(button)
                 if not chunk.last:
                     lines += self.makeLines(diff, chunk.lines[-10:],
                                             comment_lists)
                     del chunk.lines[-10:]
                 chunk.calcRange()
                 chunk.button.update()
                 if not chunk.lines:
                     lines.remove(button)
             else:
                 lines += self.makeLines(diff, chunk.lines, comment_lists)
     listwalker = urwid.SimpleFocusListWalker(lines)
     self.listbox = urwid.ListBox(listwalker)
     self._w.contents.append((self.listbox, ('weight', 1)))
     self.old_focus = 2
     self.draft_comments = []
     self._w.set_focus(self.old_focus)
     self.handleUndisplayedComments(comment_lists)
     self.app.status.update(title=self.title)