Exemple #1
0
    def onDiff(self, path, status):
        """Triggered when diff for the path is called"""
        if not path:
            return

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        try:
            # Status is one of the following:
            # IND_ADDED, IND_DELETED, IND_MERGED, IND_MODIFIED_LR, IND_MODIFIED_L, IND_CONFLICTED
            repositoryContent = ""
            localContent = ""
            if status != IND_ADDED:
                client = self.__plugin.getSVNClient(
                    self.__plugin.getSettings())
                repositoryContent = client.cat(path)
            if status != IND_DELETED:
                with open(path) as f:
                    localContent = f.read()

            diff = difflib.unified_diff(repositoryContent.splitlines(),
                                        localContent.splitlines())
            nodiffMessage = path + " has no difference to the " \
                                   "repository at revision HEAD"
            if diff is None:
                QApplication.restoreOverrideCursor()
                logging.info(nodiffMessage)
                return

            # There are changes, so replace the text and tell about the changes
            diffAsText = '\n'.join(list(diff))
            if diffAsText.strip() == '':
                QApplication.restoreOverrideCursor()
                logging.info(nodiffMessage)
                return

            source = "+++ local " + os.path.basename(path)
            diffAsText = diffAsText.replace("+++ ", source, 1)
            diffAsText = diffAsText.replace("--- ",
                                            "--- repository at revision HEAD",
                                            1)

            self.__diffViewer.setHTML(
                parse_from_memory(diffAsText, False, True))
            if not self.__diffViewer.isVisible():
                self.__onShowHideDiff()
        except Exception as exc:
            logging.error(str(exc))
        except:
            logging.error("Unknown error while calculating difference for " +
                          path)

        QApplication.restoreOverrideCursor()
Exemple #2
0
    def onDiff( self, path, status ):
        " Triggered when diff for the path is called "
        if not path:
            return

        QApplication.setOverrideCursor( QCursor( Qt.WaitCursor ) )

        try:
            # Status is one of the following:
            # IND_ADDED, IND_DELETED, IND_MERGED, IND_MODIFIED_LR, IND_MODIFIED_L, IND_CONFLICTED
            repositoryContent = ""
            localContent = ""
            if status != IND_ADDED:
                client = self.__plugin.getSVNClient( self.__plugin.getSettings() )
                repositoryContent = client.cat( path )
            if status != IND_DELETED:
                with open( path ) as f:
                    localContent = f.read()

            diff = difflib.unified_diff( repositoryContent.splitlines(),
                                         localContent.splitlines() )
            nodiffMessage = path + " has no difference to the " \
                                   "repository at revision HEAD"
            if diff is None:
                QApplication.restoreOverrideCursor()
                logging.info( nodiffMessage )
                return

            # There are changes, so replace the text and tell about the changes
            diffAsText = '\n'.join( list( diff ) )
            if diffAsText.strip() == '':
                QApplication.restoreOverrideCursor()
                logging.info( nodiffMessage )
                return

            source = "+++ local " + os.path.basename( path )
            diffAsText = diffAsText.replace( "+++ ", source, 1 )
            diffAsText = diffAsText.replace( "--- ",
                                             "--- repository at revision HEAD", 1 )

            self.__diffViewer.setHTML( parse_from_memory( diffAsText, False, True ) )
            if not self.__diffViewer.isVisible():
                self.__onShowHideDiff()
        except Exception, exc:
            logging.error( str( exc ) )
Exemple #3
0
    def onDiffBetween(self, rev, prevRev):
        """Called when diff is requested between revisions"""
        if not rev or not prevRev:
            return

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:
            lhsContent = self.__client.cat(self.__path, prevRev)
            rhsContent = self.__client.cat(self.__path, rev)
        except Exception as exc:
            QApplication.restoreOverrideCursor()
            logging.error(str(exc))
            return
        except:
            QApplication.restoreOverrideCursor()
            logging.error("Unknown error while retrieving " + self.__path +
                          " content from the repository.")
            return
        QApplication.restoreOverrideCursor()

        diff = difflib.unified_diff(lhsContent.splitlines(),
                                    rhsContent.splitlines())
        nodiffMessage = self.__path + " has no difference from revision " + \
            str(prevRev.number) + " to revision " + str(rev.number)
        if diff is None:
            logging.info(nodiffMessage)
            return

        # There are changes, so replace the text and tell about the changes
        diffAsText = '\n'.join(list(diff))
        if diffAsText.strip() == '':
            logging.info(nodiffMessage)
            return

        lhs = "--- revision " + str(prevRev.number)
        diffAsText = diffAsText.replace("--- ", lhs, 1)
        rhs = "+++ revision " + str(rev.number)
        diffAsText = diffAsText.replace("+++ ", rhs, 1)

        self.__diffViewer.setHTML(parse_from_memory(diffAsText, False, True))
        if not self.__diffViewer.isVisible():
            self.__onShowHideDiff()
Exemple #4
0
        if diff is None:
            logging.info( nodiffMessage )
            return

        # There are changes, so replace the text and tell about the changes
        diffAsText = '\n'.join( list( diff ) )
        if diffAsText.strip() == '':
            logging.info( nodiffMessage )
            return

        lhs = "--- revision " + str( prevRev.number )
        diffAsText = diffAsText.replace( "--- ", lhs, 1 )
        rhs = "+++ revision " + str( rev.number )
        diffAsText = diffAsText.replace( "+++ ", rhs, 1 )

        self.__diffViewer.setHTML( parse_from_memory( diffAsText, False, True ) )
        if not self.__diffViewer.isVisible():
            self.__onShowHideDiff()
        return

    def __onDiff( self ):
        " Show diff between revisions "
        self.onDiffBetween( self.__rhsSelected.revision,
                            self.__lhsSelected.revision )
        return

    def __onLogViewChanged( self, item, column ):
        " Revision selected for diff "
        if item.checkState( SELECT_COL ) == Qt.Checked:
            # An item has been selected
            if self.__lhsSelected is None:
Exemple #5
0
        if diff is None:
            logging.info(nodiffMessage)
            return

        # There are changes, so replace the text and tell about the changes
        diffAsText = '\n'.join(list(diff))
        if diffAsText.strip() == '':
            logging.info(nodiffMessage)
            return

        lhs = "--- revision " + str(prevRev.number)
        diffAsText = diffAsText.replace("--- ", lhs, 1)
        rhs = "+++ revision " + str(rev.number)
        diffAsText = diffAsText.replace("+++ ", rhs, 1)

        self.__diffViewer.setHTML(parse_from_memory(diffAsText, False, True))
        if not self.__diffViewer.isVisible():
            self.__onShowHideDiff()
        return

    def __onDiff(self):
        " Show diff between revisions "
        self.onDiffBetween(self.__rhsSelected.revision,
                           self.__lhsSelected.revision)
        return

    def __onLogViewChanged(self, item, column):
        " Revision selected for diff "
        if item.checkState(SELECT_COL) == Qt.Checked:
            # An item has been selected
            if self.__lhsSelected is None: