Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

changeset 1255
e1d8a8a4d40c
parent 945
8cd4d08fa9f6
child 1262
3a359afecc10
equal deleted inserted replaced
1254:c077fa008aae 1255:e1d8a8a4d40c
8 """ 8 """
9 9
10 from PyQt4.QtCore import QProcess 10 from PyQt4.QtCore import QProcess
11 11
12 from VCS.StatusMonitorThread import VcsStatusMonitorThread 12 from VCS.StatusMonitorThread import VcsStatusMonitorThread
13 from .HgClient import HgClient
13 14
14 import Preferences 15 import Preferences
15 16
16 17
17 class HgStatusMonitorThread(VcsStatusMonitorThread): 18 class HgStatusMonitorThread(VcsStatusMonitorThread):
28 @param parent reference to the parent object (QObject) 29 @param parent reference to the parent object (QObject)
29 """ 30 """
30 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent) 31 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
31 32
32 self.__ioEncoding = Preferences.getSystem("IOEncoding") 33 self.__ioEncoding = Preferences.getSystem("IOEncoding")
34
35 self.__client = None
36 self.__useCommandLine = False
33 37
34 def _performMonitor(self): 38 def _performMonitor(self):
35 """ 39 """
36 Protected method implementing the monitoring action. 40 Protected method implementing the monitoring action.
37 41
52 @return tuple of flag indicating successful operation (boolean) and 56 @return tuple of flag indicating successful operation (boolean) and
53 a status message in case of non successful operation (string) 57 a status message in case of non successful operation (string)
54 """ 58 """
55 self.shouldUpdate = False 59 self.shouldUpdate = False
56 60
57 process = QProcess() 61 if self.__client is None and not self.__useCommandLine:
62 if self.vcs.versionStr >= "1.9":
63 client = HgClient(self.projectDir, "utf-8")
64 ok, err = client.startServer()
65 if ok:
66 self.__client = client
67 else:
68 self.__useCommandLine = True
69 else:
70 self.__useCommandLine = True
71
72 # step 1: get overall status
58 args = [] 73 args = []
59 args.append('status') 74 args.append('status')
60 args.append('--noninteractive') 75 args.append('--noninteractive')
61 args.append('--all') 76 args.append('--all')
62 process.setWorkingDirectory(self.projectDir) 77
63 process.start('hg', args) 78 output = ""
64 procStarted = process.waitForStarted() 79 error = ""
65 if procStarted: 80 if self.__client:
66 finished = process.waitForFinished(300000) 81 output, error = self.__client.runcommand(args)
67 if finished and process.exitCode() == 0: 82 else:
68 output = \ 83 process = QProcess()
69 str(process.readAllStandardOutput(), self.__ioEncoding, 'replace') 84 process.setWorkingDirectory(self.projectDir)
70 states = {} 85 process.start('hg', args)
71 for line in output.splitlines(): 86 procStarted = process.waitForStarted()
72 if not line.startswith(" "): 87 if procStarted:
73 flag, name = line.split(" ", 1) 88 finished = process.waitForFinished(300000)
74 if flag in "AMR": 89 if finished and process.exitCode() == 0:
75 if flag == "R": 90 output = \
76 status = "O" 91 str(process.readAllStandardOutput(), self.__ioEncoding, 'replace')
77 else: 92 else:
78 status = flag 93 process.kill()
79 states[name] = status 94 process.waitForFinished()
80 95 error = \
81 args = [] 96 str(process.readAllStandardError(), self.__ioEncoding, 'replace')
82 args.append('resolve')
83 args.append('--list')
84 process.setWorkingDirectory(self.projectDir)
85 process.start('hg', args)
86 procStarted = process.waitForStarted()
87 if procStarted:
88 finished = process.waitForFinished(300000)
89 if finished and process.exitCode() == 0:
90 output = str(
91 process.readAllStandardOutput(), self.__ioEncoding, 'replace')
92 for line in output.splitlines():
93 flag, name = line.split(" ", 1)
94 if flag == "U":
95 states[name] = "Z" # conflict
96
97 for name in states:
98 try:
99 if self.reportedStates[name] != states[name]:
100 self.statusList.append("{0} {1}".format(states[name], name))
101 except KeyError:
102 self.statusList.append("{0} {1}".format(states[name], name))
103 for name in self.reportedStates.keys():
104 if name not in states:
105 self.statusList.append(" {0}".format(name))
106 self.reportedStates = states
107 return True, \
108 self.trUtf8("Mercurial status checked successfully")
109 else: 97 else:
110 process.kill() 98 process.kill()
111 process.waitForFinished() 99 process.waitForFinished()
112 return False, \ 100 error = self.trUtf8("Could not start the Mercurial process.")
113 str(process.readAllStandardError(), 101
114 Preferences.getSystem("IOEncoding"), 102 if error:
115 'replace') 103 return False, error
104
105 states = {}
106 for line in output.splitlines():
107 if not line.startswith(" "):
108 flag, name = line.split(" ", 1)
109 if flag in "AMR":
110 if flag == "R":
111 status = "O"
112 else:
113 status = flag
114 states[name] = status
115
116 # step 2: get conflicting changes
117 args = []
118 args.append('resolve')
119 args.append('--list')
120
121 output = ""
122 error = ""
123 if self.__client:
124 output, error = self.__client.runcommand(args)
116 else: 125 else:
117 process.kill() 126 process.setWorkingDirectory(self.projectDir)
118 process.waitForFinished() 127 process.start('hg', args)
119 return False, self.trUtf8("Could not start the Mercurial process.") 128 procStarted = process.waitForStarted()
129 if procStarted:
130 finished = process.waitForFinished(300000)
131 if finished and process.exitCode() == 0:
132 output = str(
133 process.readAllStandardOutput(), self.__ioEncoding, 'replace')
134
135 for line in output.splitlines():
136 flag, name = line.split(" ", 1)
137 if flag == "U":
138 states[name] = "Z" # conflict
139
140 # step 3: collect the status to be reported back
141 for name in states:
142 try:
143 if self.reportedStates[name] != states[name]:
144 self.statusList.append("{0} {1}".format(states[name], name))
145 except KeyError:
146 self.statusList.append("{0} {1}".format(states[name], name))
147 for name in self.reportedStates.keys():
148 if name not in states:
149 self.statusList.append(" {0}".format(name))
150 self.reportedStates = states
151
152 return True, \
153 self.trUtf8("Mercurial status checked successfully")
154
155 def _shutdown(self):
156 """
157 Protected method performing shutdown actions.
158 """
159 if self.__client:
160 self.__client.stopServer()

eric ide

mercurial