Beispiel #1
0
    def exec_(self):
        if self.expr:
            filenames = gitcmds.diff_filenames(*self.diff_arg)
        elif self.b is None:
            filenames = gitcmds.diff_index_filenames(self.a)
        else:
            filenames = gitcmds.diff_filenames(*self.diff_arg)

        if not filenames:
            details = ('"git diff --name-only %s" returned an empty list' %
                       ' '.join(self.diff_arg))
            self.hide()
            qtutils.information('git cola',
                                message='No changes to diff',
                                details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)
Beispiel #2
0
    def exec_(self):
        if self.expr:
            filenames = gitcmds.diff_filenames(*self.diff_arg)
        elif self.b is None:
            filenames = gitcmds.diff_index_filenames(self.a)
        else:
            filenames = gitcmds.diff_filenames(*self.diff_arg)

        if not filenames:
            details = ('"git diff --name-only %s" returned an empty list' %
                       ' '.join(self.diff_arg))
            self.hide()
            qtutils.information('git cola',
                                message='No changes to diff',
                                details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)
Beispiel #3
0
    def update_diff_files(self, *rest):
        """Updates the list of files whenever the selection changes"""
        # Left and Right refer to the comparison pair (l,r)
        left_item, right_item = self.selection()
        if (not left_item or not right_item or left_item == right_item):
            self.set_diff_files([])
            return
        left_item = self.remote_ref(left_item)
        right_item = self.remote_ref(right_item)

        # If any of the selection includes sandbox then we
        # generate the same diff, regardless.  This means we don't
        # support reverse diffs against sandbox aka worktree.
        if self.SANDBOX in (left_item, right_item):
            self.use_sandbox = True
            if left_item == self.SANDBOX:
                self.diff_arg = (right_item, )
            else:
                self.diff_arg = (left_item, )
        else:
            self.diff_arg = (left_item, right_item)
            self.use_sandbox = False

        # start and end as in 'git diff start end'
        self.start = left_item
        self.end = right_item

        if len(self.diff_arg) == 1:
            files = gitcmds.diff_index_filenames(self.diff_arg[0])
        else:
            files = gitcmds.diff_filenames(*self.diff_arg)

        self.set_diff_files(files)
Beispiel #4
0
    def update_diff_files(self, *rest):
        """Updates the list of files whenever the selection changes"""
        # Left and Right refer to the comparison pair (l,r)
        left_item, right_item = self.selection()
        if (not left_item or not right_item or
                left_item == right_item):
            self.set_diff_files([])
            return
        left_item = self.remote_ref(left_item)
        right_item = self.remote_ref(right_item)

        # If any of the selection includes sandbox then we
        # generate the same diff, regardless.  This means we don't
        # support reverse diffs against sandbox aka worktree.
        if self.SANDBOX in (left_item, right_item):
            self.use_sandbox = True
            if left_item == self.SANDBOX:
                self.diff_arg = (right_item,)
            else:
                self.diff_arg = (left_item,)
        else:
            self.diff_arg = (left_item, right_item)
            self.use_sandbox = False

        # start and end as in 'git diff start end'
        self.start = left_item
        self.end = right_item

        if len(self.diff_arg) == 1:
            files = gitcmds.diff_index_filenames(self.diff_arg[0])
        else:
            files = gitcmds.diff_filenames(*self.diff_arg)

        self.set_diff_files(files)
Beispiel #5
0
    def update_widgets(self, left=True):
        """Updates the list of available revisions for comparison
        """
        # This callback can be triggered by either the 'start'
        # listwidget or the 'end' list widget.  The behavior
        # is identical; the only difference is the attribute names.
        if left:
            tree_widget = self.view.descriptions_start
            revisions_param = 'revisions_start'
            revision_param = 'revision_start'
        else:
            tree_widget = self.view.descriptions_end
            revisions_param = 'revisions_end'
            revision_param = 'revision_end'

        # Is anything selected?
        id_num, selected = qtutils.selected_treeitem(tree_widget)
        if not selected:
            return

        # Is this a valid revision?
        revisionlist = self.model.param(revisions_param)
        if id_num < len(revisionlist):
            revision = self.model.param(revisions_param)[id_num]
            self.model.set_param(revision_param, revision)

        # get the changed files list
        start = self.model.revision_start
        end = self.model.revision_end
        files = gitcmds.diff_filenames(start, end)

        # get the old name of any renamed files, and prune them
        # from the changes list
        renamed_files = gitcmds.renamed_files(start, end)
        for renamed in renamed_files:
            try:
                files.remove(renamed)
            except:
                pass
        # Sets the "changed files" list
        self.model.set_compare_files(files)

        # Updates the listwidget's icons
        icon = qtutils.icon('script.png')
        for idx in xrange(0, self.view.compare_files.topLevelItemCount()):
            item = self.view.compare_files.topLevelItem(idx)
            item.setIcon(0, icon)
        # Throw the selected SHA-1 into the clipboard
        qtutils.set_clipboard(self.model.param(revision_param))
Beispiel #6
0
def diff_branch():
    """Launches a diff against a branch."""
    branch = choose_from_combo('Select Branch, Tag, or Commit-ish',
                               ['HEAD^'] +
                               cola.model().all_branches() +
                               cola.model().tags)
    if not branch:
        return
    files = gitcmds.diff_filenames(branch)
    if not files:
        qtutils.critical('No Differences',
                         'No differences found for "%s"' % branch)
        return
    filename = BrowseDialog.select_file_from_list(files)
    if not filename:
        return
    cola.notifier().broadcast(signals.branch_mode, branch, filename)
Beispiel #7
0
    def update_diff_files(self, *rest):
        """Updates the list of files whenever the selection changes"""
        if (not self.model.has_param('left_list_item') or
                not self.model.has_param('right_list_item')):
            return
        # Left and Right refer to the comparison pair (l,r)
        left_item = self.model.left_list_item
        right_item = self.model.right_list_item
        if (not left_item or not right_item or
                left_item == right_item):
            self.model.set_diff_files([])
            return
        left_item = self.remote_ref(left_item)
        right_item = self.remote_ref(right_item)

        # If any of the selection includes sandbox then we
        # generate the same diff, regardless.  This means we don't
        # support reverse diffs against sandbox aka worktree.
        if (left_item == BranchCompareController.SANDBOX or
                right_item == BranchCompareController.SANDBOX):
            self.use_sandbox = True
            if left_item == BranchCompareController.SANDBOX:
                self.diff_arg = (right_item,)
            else:
                self.diff_arg = (left_item,)
        else:
            self.diff_arg = (left_item, right_item)
            self.use_sandbox = False

        # start and end as in 'git diff start end'
        self.start = left_item
        self.end = right_item

        # TODO leverage Qt's model/view architecture
        if len(self.diff_arg) == 1:
            files = gitcmds.diff_index_filenames(self.diff_arg[0])
        else:
            files = gitcmds.diff_filenames(*self.diff_arg)
        self.model.set_diff_files(files)

        icon = qtutils.icon('script.png')
        for idx in xrange(0, self.view.diff_files.topLevelItemCount()):
            item = self.view.diff_files.topLevelItem(idx)
            item.setIcon(0, icon)
Beispiel #8
0
    def exec_(self):
        filenames = gitcmds.diff_filenames(self.diff_arg)
        if not filenames:
            details = '"git diff --name-only %s" returned an empty list' % self.diff_arg
            self.hide()
            qtutils.information("git cola", message="No changes to diff", details=details)
            self.close()
            return self.Accepted

        icon = qtutils.file_icon()
        items = []
        for filename in filenames:
            item = QtGui.QTreeWidgetItem()
            item.setIcon(0, icon)
            item.setText(0, filename)
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(filename))
            items.append(item)
        self._tree.addTopLevelItems(items)

        return QtGui.QDialog.exec_(self)