comparison hgrunner.cpp @ 107:fdca34c989c0

* Make interactivity optional in hgrunner (makes running non-interactive, local commands a bit quicker)
author Chris Cannam
date Thu, 25 Nov 2010 20:18:10 +0000
parents af314dd436d5
children 1721c580c10e
comparison
equal deleted inserted replaced
106:729438d70af8 107:fdca34c989c0
224 if (isCommandRunning()) { 224 if (isCommandRunning()) {
225 m_proc -> kill(); 225 m_proc -> kill();
226 } 226 }
227 } 227 }
228 228
229 void HgRunner::startHgCommand(QString workingDir, QStringList params) 229 void HgRunner::startHgCommand(QString workingDir, QStringList params, bool interactive)
230 { 230 {
231 #ifdef Q_OS_WIN32 231 #ifdef Q_OS_WIN32
232 // This at least means we won't block on the non-working password prompt 232 // This at least means we won't block on the non-working password prompt
233 params.push_front("ui.interactive=false"); 233 params.push_front("ui.interactive=false");
234 #else 234 #else
235 // password prompt should work here 235 // password prompt should work here
236 params.push_front("ui.interactive=true"); 236 if (interactive) {
237 params.push_front("ui.interactive=true");
238 } else {
239 params.push_front("ui.interactive=false");
240 }
237 #endif 241 #endif
238 params.push_front("--config"); 242 params.push_front("--config");
239 startCommand(getHgBinaryName(), workingDir, params); 243 startCommand(getHgBinaryName(), workingDir, params, interactive);
240 } 244 }
241 245
242 void HgRunner::startCommand(QString command, QString workingDir, QStringList params) 246 void HgRunner::startCommand(QString command, QString workingDir, QStringList params,
247 bool interactive)
243 { 248 {
244 m_isRunning = true; 249 m_isRunning = true;
245 setRange(0, 0); 250 setRange(0, 0);
246 setVisible(true); 251 setVisible(true);
247 m_output.clear(); 252 m_output.clear();
253 if (!workingDir.isEmpty()) { 258 if (!workingDir.isEmpty()) {
254 m_proc->setWorkingDirectory(workingDir); 259 m_proc->setWorkingDirectory(workingDir);
255 } 260 }
256 261
257 m_procInput = 0; 262 m_procInput = 0;
263 m_ptySlaveFilename = "";
264
258 #ifndef Q_OS_WIN32 265 #ifndef Q_OS_WIN32
259 char name[1024]; 266 if (interactive) {
260 if (openpty(&m_ptyMasterFd, &m_ptySlaveFd, name, NULL, NULL)) { 267 char name[1024];
261 perror("openpty failed"); 268 if (openpty(&m_ptyMasterFd, &m_ptySlaveFd, name, NULL, NULL)) {
262 } else { 269 perror("openpty failed");
263 DEBUG << "openpty succeeded: master " << m_ptyMasterFd 270 } else {
264 << " slave " << m_ptySlaveFd << " filename " << name << endl; 271 DEBUG << "openpty succeeded: master " << m_ptyMasterFd
265 m_procInput = new QFile; 272 << " slave " << m_ptySlaveFd << " filename " << name << endl;
266 m_procInput->open(m_ptyMasterFd, QFile::WriteOnly); 273 m_procInput = new QFile;
267 m_ptySlaveFilename = name; 274 m_procInput->open(m_ptyMasterFd, QFile::WriteOnly);
268 m_proc->setStandardInputFile(m_ptySlaveFilename); 275 m_ptySlaveFilename = name;
269 ::close(m_ptySlaveFd); 276 m_proc->setStandardInputFile(m_ptySlaveFilename);
277 ::close(m_ptySlaveFd);
278 }
270 } 279 }
271 #endif 280 #endif
272 281
273 m_lastHgCommand = command; 282 m_lastHgCommand = command;
274 m_lastParams = params.join(" "); 283 m_lastParams = params.join(" ");