Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

tortoise\shellext: use new dirstate.cpp for overlays

This now reads hg's dirstate file directly from the C++ shell extension to
determine the overlay icons, instead of querying the separate python
server process.

(Code copied and adapted from CuteHg project)

Changeset eb2ded6ea314

Parent 9fa35043dbbf

by Adrian Buehlmann

Changes to 6 files · Browse files at eb2ded6ea314 Showing diff from parent 9fa35043dbbf Diff from another changeset...

 
3
4
5
 
 
 
 
 
6
7
8
 
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
 
 
 
 
 
 
 
66
67
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
70
71
 
72
73
74
 
75
76
 
77
78
 
3
4
5
6
7
8
9
10
11
12
13
 
56
57
58
 
59
60
61
 
 
62
63
64
 
65
 
66
67
68
69
70
71
72
73
74
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
 
102
103
 
 
104
105
 
106
107
108
@@ -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
9
10
11
 
 
12
13
14
 
8
9
10
 
11
12
13
14
15
@@ -8,7 +8,8 @@
  PipeUtils.o \   ShellUtils2.o \   StringUtils.o \ - dirstate.o + dirstate.o \ + common.o    DEFFILE=ShellExt.def  
Change 1 of 1 Show Entire File tortoise/​shellext/​common.cpp Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@@ -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; +} +
Change 1 of 1 Show Entire File tortoise/​shellext/​common.h Stacked
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
@@ -0,0 +1,8 @@
+#ifndef _COMMON_H +#define _COMMON_H + +#include <string> + +bool HgFindRoot(char* path, std::string* root); + +#endif
 
14
15
16
 
 
17
18
19
 
113
114
115
116
117
118
119
 
258
259
260
 
 
261
 
262
263
264
 
 
265
 
266
267
268
 
334
335
336
 
 
 
337
 
 
338
 
 
 
 
339
340
341
342
343
 
344
 
345
346
347
 
14
15
16
17
18
19
20
21
 
115
116
117
 
118
119
120
 
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
 
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
@@ -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 != '?';   }   }
Change 1 of 1 Show Entire File tortoise/​shellext/​dirstate.h Stacked
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
@@ -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