Changeset c8bf2745ce7d…
Parent 55f1636e455c…
by
Changes to 4 files · Browse files at c8bf2745ce7d Showing diff from parent 55f1636e455c Diff from another changeset...
@@ -6,7 +6,7 @@ #include <stdio.h>
#include <vector>
-void CShellExt::DoHgProc(const std::string &cmd, bool nofiles, bool nogui)
+void CShellExt::DoHgProc(const std::string &cmd)
{
std::string dir = GetTHgProgRoot();
TDEBUG_TRACE("DoHgProc: THG root = " << dir);
@@ -15,10 +15,7 @@ TDEBUG_TRACE("DoHgProc: THG root is empty");
return;
}
- std::string hgcmd = Quote(dir + "\\hgproc.bat") + " --command " + cmd;
-
- if (nogui)
- hgcmd += " --nogui";
+ std::string hgcmd = Quote(dir + "\\hgtk.exe") + cmd;
std::string cwd;
std::vector<std::string> filelist;
@@ -38,34 +35,10 @@ return;
}
- hgcmd += " --cwd " + Quote(cwd);
- hgcmd += " --root " + Quote(GetHgRepoRoot(cwd));
+ if (!filelist.empty())
+ hgcmd += " --listfile -";
- if (!nofiles)
- {
- std::string tempfile = GetTemporaryFile();
- SECURITY_ATTRIBUTES sa;
- memset(&sa, 0, sizeof(sa));
- sa.nLength = sizeof(sa);
- sa.bInheritHandle = TRUE;
-
- TDEBUG_TRACE("DoHgProc: temp file = " << tempfile);
- HANDLE tempfileHandle = CreateFileA(tempfile.c_str(), GENERIC_WRITE,
- FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
-
- for (int i=0; i<filelist.size(); i++)
- {
- DWORD dwWritten;
- TDEBUG_TRACE("DoHgProc: temp file adding " << filelist[i]);
- WriteFile(tempfileHandle, filelist[i].c_str(),
- static_cast<DWORD>(filelist[i].size()), &dwWritten, 0);
- }
- CloseHandle(tempfileHandle);
- hgcmd += " --listfile " + Quote(tempfile);
- hgcmd += " --deletelistfile" ;
- }
-
- LaunchCommand(hgcmd);
+ LaunchCommand(hgcmd, cwd, filelist);
}
STDMETHODIMP
@@ -136,7 +109,7 @@CShellExt::CM_Userconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd,
LPCSTR pszParam, int iShowCmd)
{
- DoHgProc("config", true);
+ DoHgProc("userconfig");
return NOERROR;
}
@@ -144,6 +117,6 @@CShellExt::CM_Repoconf(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd,
LPCSTR pszParam, int iShowCmd)
{
- DoHgProc("config");
+ DoHgProc("repoconfig");
return NOERROR;
}
|
@@ -67,7 +67,7 @@ std::string myFolder;
protected:
- void CShellExt::DoHgProc(const std::string &, bool=false, bool=false);
+ void CShellExt::DoHgProc(const std::string &);
public:
// context menu actions
|
|
@@ -91,27 +91,76 @@ // Note: if the command is a batch file and the [full] path to the
// batch contains spaces, the path must be double-quoted.
// (see http://www.encocoservices.com/createprocess.html)
-bool LaunchCommand(const std::string& command, bool minimized)
+bool LaunchCommand(const std::string& command, const std::string& cwd, std::vector<std::string> filelist)
{
TDEBUG_TRACE("LaunchCommand: " << command);
PROCESS_INFORMATION processInfo;
+ memset(&processInfo, 0, sizeof(processInfo));
+
+ HANDLE hChildStd_IN_Rd = NULL;
+ HANDLE hChildStd_IN_Wr = NULL;
+
+ SECURITY_ATTRIBUTES saAttr;
+ // Set the bInheritHandle flag so pipe handles are inherited.
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ saAttr.bInheritHandle = TRUE;
+ saAttr.lpSecurityDescriptor = NULL;
+
+ // Create a pipe for the child process's STDIN.
+ if (!CreatePipe(&hChildStd_IN_Rd, &hChildStd_IN_Wr, &saAttr, 0))
+ {
+ TDEBUG_TRACE("LaunchCommand: unable to create stdin pipe");
+ return false;
+ }
+
+ // Ensure the write handle to the pipe for STDIN is not inherited.
+ if (!SetHandleInformation(hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
+ {
+ TDEBUG_TRACE("LaunchCommand: unable to clear stdin write handle");
+ return false;
+ }
+
STARTUPINFOA startupInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
- startupInfo.dwFlags = minimized ? STARTF_USESHOWWINDOW : 0;
- startupInfo.wShowWindow = SW_SHOWMINIMIZED;
- int res = CreateProcessA(0,
+ startupInfo.hStdInput = hChildStd_IN_Rd;
+ startupInfo.dwFlags |= STARTF_USESTDHANDLES;
+
+ int res = CreateProcessA(NULL, // No module name, use command line
const_cast<char*>(command.c_str()),
- 0, 0,
+ NULL, // Process handle not inherited
+ NULL, // Thread handle not inherited
FALSE,
CREATE_NO_WINDOW,
- 0, 0, &startupInfo, &processInfo);
- TDEBUG_TRACE("LaunchCommand: res = " << res);
+ NULL, // use parent's environment
+ const_cast<char*>(cwd.c_str()),
+ &startupInfo,
+ &processInfo);
if (res == 0)
{
+ TDEBUG_TRACE("LaunchCommand: failed to launch");
return false;
}
+ std::string writename;
+ for( DWORD i = 0 ; i < filelist.size(); i++ )
+ {
+ bool bSuccess;
+ DWORD dwWritten;
+
+ writename = filelist[i];
+ writename.push_back('\n');
+
+ bSuccess = WriteFile(hChildStd_IN_Wr, writename.c_str(), writename.size(), &dwWritten, NULL);
+ if ( !bSuccess )
+ break;
+ }
+
+ if ( !CloseHandle(hChildStd_IN_Wr) )
+ {
+ TDEBUG_TRACE("LaunchCommand: Unable to close process stdin");
+ }
+
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
return true;
@@ -209,3 +258,4 @@{
return !GetHgRepoRoot(path).empty();
}
+
|
@@ -31,7 +31,7 @@ bool IsDirectory(const std::string&);
std::string DirName(const std::string&);
std::string BaseName(const std::string&);
-bool LaunchCommand(const std::string& command, bool minimized=false);
+bool LaunchCommand(const std::string& command, const std::string& cwd, const std::vector<std::string> filelist);
HICON GetTortoiseIcon(const std::string & iconname);
std::string GetHgRepoRoot(const std::string& path);
bool IsHgRepo(const std::string& path);
|
Loading...