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

dirstate: use std::string for relpath param

Changeset 8e6c2ef3d883

Parent ceb80b618ae3

by Adrian Buehlmann

Changes to 3 files · Browse files at 8e6c2ef3d883 Showing diff from parent ceb80b618ae3 Diff from another changeset...

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
55
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
109
110
111
112
113
114
115
116
117
118
119
120
121
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
55
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
109
110
111
112
113
114
115
116
117
118
119
120
 #include "stdafx.h"  #include "ShellExt.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "PipeUtils.h"  #include "dirstate.h"    #include <shlwapi.h>      STDMETHODIMP CShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax,   int *pIndex, DWORD *pdwFlags)  {   *pIndex = 0;   *pdwFlags = ISIOI_ICONFILE;     // get installation path   std::string dir = GetTHgProgRoot();   if (dir.empty())   {   TDEBUG_TRACE("GetOverlayInfo: THG root is empty");   wcsncpy(pwszIconFile, L"", cchMax);   return S_OK;   }     // find icon per overlay type   std::wstring dirWide = MultibyteToWide(dir);   wcsncpy(pwszIconFile, dirWide.c_str(), cchMax);   cchMax -= static_cast<int>(dirWide.size()) + 1;  /*   switch (myTortoiseClass)   {   case TORTOISE_OLE_ADDED:   wcsncat(pwszIconFile, L"\\icons\\status\\added.ico", cchMax);   break;   case TORTOISE_OLE_MODIFIED:   wcsncat(pwszIconFile, L"\\icons\\status\\changed.ico", cchMax);   break;   case TORTOISE_OLE_UNCHANGED:   wcsncat(pwszIconFile, L"\\icons\\status\\unchanged.ico", cchMax);   break;   default:   break;   }  */   std::string path = WideToMultibyte(pwszIconFile);   TDEBUG_TRACE("GetOverlayInfo: icon path = " << path);     return S_OK;  }    STDMETHODIMP CShellExt::GetPriority(int *pPriority)  {   *pPriority = 1;   return S_OK;  }      STDMETHODIMP CShellExt::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)  {   std::string mbstr = WideToMultibyte(pwszPath);     TDEBUG_TRACE("IsMemberOf: search for " << mbstr.c_str());     char path[MAX_PATH] = "";   strncat(path, mbstr.c_str(), MAX_PATH);     std::string hgroot = GetHgRepoRoot(path);     if (hgroot.empty())   {   TDEBUG_TRACE("IsMemberOf: Not a Hg repo (hgroot is empty)");   return S_FALSE;   }     TDEBUG_TRACE("IsMemberOf: hgroot = " << hgroot);     size_t offset = hgroot.length();   if (path[offset] == '\\')   offset++;   const char* relpathptr = path + offset;   - char relpath[MAX_PATH] = ""; - strncat(relpath, relpathptr, MAX_PATH); + std::string relpath = relpathptr;     char status = 0;     if (PathIsDirectory(path))   { - if (!strlen(relpath)) + if (relpath.size() == 0)   return S_FALSE; // don't show icon on repo root dir   - if (strncmp(relpath, ".hg", 3) == 0) + if (relpath.compare(0, 3, ".hg") == 0)   return S_FALSE; // don't descend into .hg dir     if (!HgQueryDirstateDirectory(hgroot.c_str(), path, relpath, status))   {   TDEBUG_TRACE("IsMemberOf: HgQueryDirstateDirectory returns false");   return S_FALSE;   }   }   else   {   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 && status == 'M')   return S_OK;   else if (myTortoiseClass == TORTOISE_OLE_UNCHANGED && status == 'C')   return S_OK;     return S_FALSE;  }
 
229
230
231
232
 
233
234
235
 
245
246
247
248
 
249
250
251
 
 
252
253
254
 
256
257
258
259
 
 
260
261
262
263
264
 
265
266
267
 
269
270
271
272
 
273
274
275
276
277
278
 
279
280
281
 
315
316
317
318
 
 
319
320
321
 
323
324
325
326
 
327
328
329
330
331
332
333
 
334
335
336
337
 
338
339
 
340
341
342
 
229
230
231
 
232
233
234
235
 
245
246
247
 
248
249
 
 
250
251
252
253
254
 
256
257
258
 
259
260
261
262
263
264
 
265
266
267
268
 
270
271
272
 
273
274
275
276
277
278
 
279
280
281
282
 
316
317
318
 
319
320
321
322
323
 
325
326
327
 
328
329
330
331
332
333
334
 
335
336
337
338
 
339
340
 
341
342
343
344
@@ -229,7 +229,7 @@
     int HgQueryDirstate( - const char* hgroot, const char* abspath, char* relpathloc, + const char* hgroot, const char* abspath, std::string& relpath,   const dirstate*& ppd, struct _stat& rstat)  {   if (0 != lstat(abspath, rstat)) @@ -245,10 +245,10 @@
  return 0;   }   - for (char* t = relpathloc; *t; ++t) + for (size_t i = 0; i < relpath.size(); ++i)   { - if (*t == '\\') - *t = '/'; + if (relpath[i] == '\\') + relpath[i] = '/';   }     return 1; @@ -256,12 +256,13 @@
     int HgQueryDirstateDirectory( - const char* hgroot, const char* abspath, char* relpathloc, char& outStatus) + const char* hgroot, const char* abspath, + std::string& relpath, char& outStatus)  {   const dirstate* pd = 0;   struct _stat stat;   - if (!HgQueryDirstate(hgroot, abspath, relpathloc, pd, stat)) + if (!HgQueryDirstate(hgroot, abspath, relpath, pd, stat))   return 0;     bool added = false; @@ -269,13 +270,13 @@
  bool empty = true;     size_t rootlen = strlen(hgroot); - size_t len = strlen(relpathloc); + size_t len = relpath.size();     for (unsigned ix = 0; ix < pd->entries.size() && !modified; ix++)   {   const direntry& e = pd->entries[ix];   - if (0 != strncmp(relpathloc, e.name.c_str(), len)) + if (e.name.compare(0, len, relpath) != 0)   continue;     empty = false; @@ -315,7 +316,8 @@
     int HgQueryDirstateFile( - const char* hgroot, const char* abspath, char* relpathloc, char& outStatus) + const char* hgroot, const char* abspath, + std::string& relpath, char& outStatus)  {   const dirstate* pd = 0;   struct _stat stat; @@ -323,20 +325,20 @@
  TDEBUG_TRACE("HgQueryDirstateFile: search for " << abspath);   TDEBUG_TRACE("HgQueryDirstateFile: hgroot = " << hgroot);   - if (!HgQueryDirstate(hgroot, abspath, relpathloc, pd, stat)) + if (!HgQueryDirstate(hgroot, abspath, relpath, pd, stat))   {   TDEBUG_TRACE("HgQueryDirstateFile: HgQueryDirstate returns false");   return 0;   }     TDEBUG_TRACE("HgQueryDirstateFile: pd->entries.size() = " << pd->entries.size()); - TDEBUG_TRACE("HgQueryDirstateFile: relpathloc = " << relpathloc); + TDEBUG_TRACE("HgQueryDirstateFile: relpath = " << relpath);     for (unsigned ix = 0; ix < pd->entries.size(); ix++)   { - if (0 == strncmp(relpathloc, pd->entries[ix].name.c_str(), MAX_PATH)) + if (relpath == pd->entries[ix].name)   { - TDEBUG_TRACE("HgQueryDirstateFile: found relpathloc"); + TDEBUG_TRACE("HgQueryDirstateFile: found relpath");   outStatus = mapdirstate(pd->entries[ix], stat);   TDEBUG_TRACE("HgQueryDirstateFile: outStatus = " << outStatus);   return outStatus != '?';
 
1
2
3
 
 
4
5
 
6
7
8
 
9
10
 
1
2
3
4
5
6
 
7
8
9
 
10
11
12
@@ -1,10 +1,12 @@
 #ifndef _DIRSTATE_H  #define _DIRSTATE_H   +#include <string> +  int HgQueryDirstateFile( - const char* hgroot, const char* abspath, char* relpathloc, char& outStatus); + const char* hgroot, const char* abspath, std::string& relpath, char& outStatus);    int HgQueryDirstateDirectory( - const char* hgroot, const char* abspath, char* relpathloc, char& outStatus); + const char* hgroot, const char* abspath, std::string& relpath, char& outStatus);    #endif