| 731 | |
| 732 | |
| 733 | void GitRepository::computePercentComplete() |
| 734 | // ---------------------------------------------------------------------------- |
| 735 | // Extract % complete from the text output of a clone/fetch/push process |
| 736 | // ---------------------------------------------------------------------------- |
| 737 | { |
| 738 | GitProcess *cmd = (GitProcess *)sender(); |
| 739 | int &pos = cmd->errPos; |
| 740 | bool matched = false; |
| 741 | int percent = -1; |
| 742 | do |
| 743 | { |
| 744 | // The percent points allocated to each of the 3 phases below |
| 745 | // (compressing, receiving, resolving). |
| 746 | // Phases #1 and #3 are typically much faster than #2 so we give them |
| 747 | // less weight. |
| 748 | int p1 = 5, p2 = 94, p3 = 1; |
| 749 | QString str = cmd->err.mid(pos); |
| 750 | QRegExp rx1("Compressing objects: +([0-9]*)%"); |
| 751 | QRegExp rx2("Receiving objects: +([0-9]*)%"); |
| 752 | QRegExp rx3("Resolving deltas: +([0-9]*)%"); |
| 753 | matched = true; |
| 754 | if (rx1.indexIn(str) != -1) |
| 755 | { |
| 756 | percent = rx1.cap(1).toInt() * p1 / 100; |
| 757 | pos += rx1.matchedLength(); |
| 758 | } |
| 759 | else |
| 760 | if (rx2.indexIn(str) != -1) |
| 761 | { |
| 762 | percent = p1 + rx2.cap(1).toInt() * p2 / 100; |
| 763 | pos += rx2.matchedLength(); |
| 764 | } |
| 765 | else |
| 766 | if (rx3.indexIn(str) != -1) |
| 767 | { |
| 768 | percent = p1 + p2 + rx3.cap(1).toInt() * p3 / 100; |
| 769 | pos += rx3.matchedLength(); |
| 770 | } |
| 771 | else |
| 772 | { |
| 773 | matched = false; |
| 774 | } |
| 775 | } |
| 776 | while (matched); |
| 777 | |
| 778 | if (percent == -1 || percent == cmd->percent) |
| 779 | return; |
| 780 | |
| 781 | IFTRACE(process) |
| 782 | std::cerr << "Process " << cmd->num << ": " << percent << "% complete\n"; |
| 783 | cmd->percent = percent; |
| 784 | emit percentComplete(percent); |
| 785 | } |
| 786 | |
| 787 | |
| 788 | void GitRepository::asyncProcessFinished(int exitCode, QProcess::ExitStatus st) |