1626 from .HgDiffDialog import HgDiffDialog |
1629 from .HgDiffDialog import HgDiffDialog |
1627 self.diff = HgDiffDialog(self) |
1630 self.diff = HgDiffDialog(self) |
1628 self.diff.show() |
1631 self.diff.show() |
1629 self.diff.start(name, revisions) |
1632 self.diff.start(name, revisions) |
1630 |
1633 |
1631 def hgSbsDiff(self, name): |
1634 def __hgGetFileForRevision(self, name, rev=""): |
1632 """ |
1635 """ |
1633 Public method used to view the difference of a file to the Mercurial repository |
1636 Private method to get a file for a specific revision from the repository. |
1634 side-by-side. |
1637 |
1635 |
1638 @param name file name to get from the repository (string) |
1636 @param name file name to be diffed (string) |
1639 @keyparam rev revision to retrieve (string) |
1637 """ |
1640 @return contents of the file (string) and an error message (string) |
1638 if isinstance(name, list): |
1641 """ |
1639 raise ValueError("Wrong parameter type") |
|
1640 |
|
1641 args = [] |
1642 args = [] |
1642 args.append("cat") |
1643 args.append("cat") |
|
1644 if rev: |
|
1645 args.append("--rev") |
|
1646 args.append(rev) |
1643 args.append(name) |
1647 args.append(name) |
1644 |
1648 |
1645 output1 = "" |
|
1646 if self.__client is None: |
1649 if self.__client is None: |
|
1650 output = "" |
|
1651 error = "" |
|
1652 |
1647 # find the root of the repo |
1653 # find the root of the repo |
1648 repodir = self.splitPath(name)[0] |
1654 repodir = self.splitPath(name)[0] |
1649 while not os.path.isdir(os.path.join(repodir, self.adminDir)): |
1655 while not os.path.isdir(os.path.join(repodir, self.adminDir)): |
1650 repodir = os.path.dirname(repodir) |
1656 repodir = os.path.dirname(repodir) |
1651 if os.path.splitdrive(repodir)[1] == os.sep: |
1657 if os.path.splitdrive(repodir)[1] == os.sep: |
1655 process.setWorkingDirectory(repodir) |
1661 process.setWorkingDirectory(repodir) |
1656 process.start('hg', args) |
1662 process.start('hg', args) |
1657 procStarted = process.waitForStarted(5000) |
1663 procStarted = process.waitForStarted(5000) |
1658 if procStarted: |
1664 if procStarted: |
1659 finished = process.waitForFinished(30000) |
1665 finished = process.waitForFinished(30000) |
1660 if finished and process.exitCode() == 0: |
1666 if finished: |
1661 output1 = str(process.readAllStandardOutput(), |
1667 if process.exitCode() == 0: |
1662 Preferences.getSystem("IOEncoding"), 'replace') |
1668 output = str(process.readAllStandardOutput(), |
1663 else: |
1669 Preferences.getSystem("IOEncoding"), 'replace') |
1664 output1, error = self.__client.runcommand(args) |
1670 else: |
1665 |
1671 error = str(process.readAllStandardError(), |
1666 try: |
1672 Preferences.getSystem("IOEncoding"), 'replace') |
1667 f1 = open(name, "r", encoding="utf-8") |
1673 else: |
1668 output2 = f1.read() |
1674 error = self.trUtf8("The hg process did not finish within 30s.") |
1669 f1.close() |
1675 else: |
1670 except IOError: |
1676 error = self.trUtf8('The process {0} could not be started. ' |
|
1677 'Ensure, that it is in the search path.').format('hg') |
|
1678 else: |
|
1679 output, error = self.__client.runcommand(args) |
|
1680 |
|
1681 return output, error |
|
1682 |
|
1683 def hgSbsDiff(self, name, extended=False, revisions=None): |
|
1684 """ |
|
1685 Public method used to view the difference of a file to the Mercurial repository |
|
1686 side-by-side. |
|
1687 |
|
1688 @param name file name to be diffed (string) |
|
1689 @keyparam extended flag indicating the extended variant (boolean) |
|
1690 @keyparam revisions tuple of two revisions (tuple of strings) |
|
1691 """ |
|
1692 if isinstance(name, list): |
|
1693 raise ValueError("Wrong parameter type") |
|
1694 |
|
1695 if extended: |
|
1696 # find the root of the repo |
|
1697 repodir = self.splitPath(name)[0] |
|
1698 while not os.path.isdir(os.path.join(repodir, self.adminDir)): |
|
1699 repodir = os.path.dirname(repodir) |
|
1700 if os.path.splitdrive(repodir)[1] == os.sep: |
|
1701 return |
|
1702 |
|
1703 if self.isExtensionActive("bookmarks"): |
|
1704 bookmarksList = \ |
|
1705 self.getExtensionObject("bookmarks").hgGetBookmarksList(repodir) |
|
1706 else: |
|
1707 bookmarksList = None |
|
1708 |
|
1709 from .HgRevisionsSelectionDialog import HgRevisionsSelectionDialog |
|
1710 dlg = HgRevisionsSelectionDialog(self.hgGetTagsList(repodir), |
|
1711 self.hgGetBranchesList(repodir), |
|
1712 bookmarksList) |
|
1713 if dlg.exec_() == QDialog.Accepted: |
|
1714 rev1, rev2 = dlg.getRevisions() |
|
1715 elif revisions: |
|
1716 rev1, rev2 = revisions[0], revisions[1] |
|
1717 else: |
|
1718 rev1, rev2 = "", "" |
|
1719 |
|
1720 output1, error = self.__hgGetFileForRevision(name, rev=rev1) |
|
1721 if error: |
1671 E5MessageBox.critical(self, |
1722 E5MessageBox.critical(self, |
1672 self.trUtf8("Mercurial Side-by-Side Difference"), |
1723 self.trUtf8("Mercurial Side-by-Side Difference"), |
1673 self.trUtf8("""<p>The file <b>{0}</b> could not be read.</p>""") |
1724 error) |
1674 .format(name)) |
|
1675 return |
1725 return |
|
1726 name1 = "{0} (rev. {1})".format(name, rev1 and rev1 or ".") |
|
1727 |
|
1728 if rev2: |
|
1729 output2, error = self.__hgGetFileForRevision(name, rev=rev2) |
|
1730 if error: |
|
1731 E5MessageBox.critical(self, |
|
1732 self.trUtf8("Mercurial Side-by-Side Difference"), |
|
1733 error) |
|
1734 return |
|
1735 name2 = "{0} (rev. {1})".format(name, rev2) |
|
1736 else: |
|
1737 try: |
|
1738 f1 = open(name, "r", encoding="utf-8") |
|
1739 output2 = f1.read() |
|
1740 f1.close() |
|
1741 name2 = name |
|
1742 except IOError: |
|
1743 E5MessageBox.critical(self, |
|
1744 self.trUtf8("Mercurial Side-by-Side Difference"), |
|
1745 self.trUtf8("""<p>The file <b>{0}</b> could not be read.</p>""") |
|
1746 .format(name)) |
|
1747 return |
1676 |
1748 |
1677 if output1 and output2: |
1749 if output1 and output2: |
1678 from UI.CompareDialog import CompareDialog |
1750 if self.sbsDiff is None: |
1679 self.sbsDiff = CompareDialog() |
1751 from UI.CompareDialog import CompareDialog |
|
1752 self.sbsDiff = CompareDialog() |
1680 self.sbsDiff.show() |
1753 self.sbsDiff.show() |
1681 self.sbsDiff.compare(output1, output2, "{0}@.".format(name), name) |
1754 self.sbsDiff.compare(output1, output2, name1, name2) |
1682 |
1755 |
1683 def hgLogBrowser(self, path): |
1756 def hgLogBrowser(self, path): |
1684 """ |
1757 """ |
1685 Public method used to browse the log of a file/directory from the |
1758 Public method used to browse the log of a file/directory from the |
1686 Mercurial repository. |
1759 Mercurial repository. |