Changeset eb2ded6ea314…
Parent 9fa35043dbbf…
by
Changes to 6 files · Browse files at eb2ded6ea314 Showing diff from parent 9fa35043dbbf Diff from another changeset...
@@ -3,6 +3,11 @@ #include "TortoiseUtils.h"
#include "StringUtils.h"
#include "PipeUtils.h"
+#include "common.h"
+#include "dirstate.h"
+
+#include <shlwapi.h>
+
STDMETHODIMP CShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax,
int *pIndex, DWORD *pdwFlags)
@@ -51,28 +56,53 @@ return S_OK;
}
-#define BUFSIZE 512
STDMETHODIMP CShellExt::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)
{
- TCHAR status[BUFSIZE] = TEXT("");
- int bufsize = BUFSIZE * sizeof(TCHAR);
std::string mbstr = WideToMultibyte(pwszPath);
TDEBUG_TRACE("IsMemberOf: search for " << mbstr.c_str());
- int cbRead = query_pipe(mbstr.c_str(), status, bufsize);
- if (cbRead < 0)
+ char path[MAX_PATH] = "";
+ strncat(path, mbstr.c_str(), MAX_PATH);
+
+ std::string hgroot;
+
+ if (!HgFindRoot(path, &hgroot))
+ {
+ TDEBUG_TRACE("IsMemberOf: HgFindRoot returns false");
return S_FALSE;
- else if (myTortoiseClass == TORTOISE_OLE_ADDED &&
- strcmp(status, "added") == 0)
+ }
+
+ TDEBUG_TRACE("IsMemberOf: hgroot = " << hgroot);
+
+ if (PathIsDirectory(path))
+ return S_FALSE;
+
+ size_t offset = hgroot.length();
+ if (path[offset] == '\\')
+ offset++;
+ const char* relpathptr = path + offset;
+
+ char relpath[MAX_PATH] = "";
+ strncat(relpath, relpathptr, MAX_PATH);
+
+ char status = 0;
+
+ if (!HgQueryDirstateFile(hgroot.c_str(), path, relpath, &status))
+ {
+ TDEBUG_TRACE("IsMemberOf: HgQueryDirstateFile returns false");
+ return S_FALSE;
+ }
+
+ TDEBUG_TRACE("IsMemberOf: status = " << status);
+
+ if (myTortoiseClass == TORTOISE_OLE_ADDED && status == 'A')
return S_OK;
- else if (myTortoiseClass == TORTOISE_OLE_MODIFIED &&
- strcmp(status, "modified") == 0)
+ else if (myTortoiseClass == TORTOISE_OLE_MODIFIED && status == 'M')
return S_OK;
- else if (myTortoiseClass == TORTOISE_OLE_UNCHANGED &&
- strcmp(status, "unchanged") == 0)
+ else if (myTortoiseClass == TORTOISE_OLE_UNCHANGED && status == 'C')
return S_OK;
-
+
return S_FALSE;
}
|
@@ -8,7 +8,8 @@ PipeUtils.o \
ShellUtils2.o \
StringUtils.o \
- dirstate.o
+ dirstate.o \
+ common.o
DEFFILE=ShellExt.def
|
|
@@ -0,0 +1,54 @@ + // CuteHg - Qt4 Dialog Extension of Mercurial
+// Copyright (C) 2009 Stefan Rusek
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <string>
+#include <shlwapi.h>
+
+
+bool HgFindRoot(char* path, std::string* root)
+{
+ char temp1[MAX_PATH];
+ char temp2[MAX_PATH];
+
+ char* dir = temp1;
+ char* other = temp2;
+
+ if (!GetFullPathName(path, MAX_PATH, dir, NULL))
+ return false;
+
+ bool found = false;
+ while (dir)
+ {
+ other = PathCombine(other, dir, ".\\.hg\\store");
+ if (found = PathIsDirectory(other))
+ break;
+
+ // search parent
+ if (PathIsRoot(dir))
+ dir = NULL;
+ else
+ {
+ char* temp = PathCombine(other, dir, "..");
+ other = dir;
+ dir = temp;
+ }
+ }
+
+ if (found)
+ *root = dir;
+ return found;
+}
+
|
|
@@ -0,0 +1,8 @@ + #ifndef _COMMON_H
+#define _COMMON_H
+
+#include <string>
+
+bool HgFindRoot(char* path, std::string* root);
+
+#endif
|
@@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include "stdafx.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
@@ -113,7 +115,6 @@}
-typedef unsigned long uint32_t;
static uint32_t ntohl(uint32_t x)
{
return ((x & 0x000000ffUL) << 24) |
@@ -258,11 +259,17 @@ char* temp;
if (0 != lstat(abspath, pstat))
+ {
+ TDEBUG_TRACE("HgQueryDirstate: lstat returns non-null");
return 0;
+ }
*ppd = dirstate_get(hgroot);
if (!*ppd)
+ {
+ TDEBUG_TRACE("HgQueryDirstate: dirstate_get returns NULL");
return 0;
+ }
temp = relpathloc;
while (*temp)
@@ -334,14 +341,25 @@ struct _stat stat;
unsigned ix;
+ TDEBUG_TRACE("HgQueryDirstateFile: search for " << abspath);
+ TDEBUG_TRACE("HgQueryDirstateFile: hgroot = " << hgroot);
+
if (!HgQueryDirstate(hgroot, abspath, relpathloc, &pd, &stat))
+ {
+ TDEBUG_TRACE("HgQueryDirstateFile: HgQueryDirstate returns false");
return 0;
+ }
+
+ TDEBUG_TRACE("HgQueryDirstateFile: pd->num_entries = " << pd->num_entries);
+ TDEBUG_TRACE("HgQueryDirstateFile: relpathloc = " << relpathloc);
for (ix = 0; ix < pd->num_entries; ix++)
{
if (0 == strncmp(relpathloc, pd->entries[ix].name, MAX_PATH))
{
+ TDEBUG_TRACE("HgQueryDirstateFile: found relpathloc");
*outStatus = mapdirstate(&pd->entries[ix], &stat);
+ TDEBUG_TRACE("HgQueryDirstateFile: *outStatus = " << *outStatus);
return *outStatus != '?';
}
}
|
|
@@ -0,0 +1,8 @@ + #ifndef _DIRSTATE_H
+#define _DIRSTATE_H
+
+int HgQueryDirstateFile(const char* hgroot, const char* abspath, char* relpathloc, char* outStatus);
+
+int HgQueryDirstateDirectory(const char* hgroot, char* abspath, char* relpathloc, char* outStatus);
+
+#endif
|
Loading...