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

merge with crew

Changeset a7d8c476ee18

Parents 72a091dde1e2

Parents 887f8ef3312a

by Adrian Buehlmann

Changes to 5 files · Browse files at a7d8c476ee18 Showing diff from parent 72a091dde1e2 887f8ef3312a Diff from another changeset...

 
113
114
115
116
 
117
118
119
 
123
124
125
126
127
 
 
128
129
130
 
136
137
138
139
 
140
141
142
 
161
162
163
164
 
165
166
167
 
186
187
188
189
 
190
191
192
 
225
226
227
228
 
229
230
231
 
460
461
462
463
 
464
465
466
 
113
114
115
 
116
117
118
119
 
123
124
125
 
 
126
127
128
129
130
 
136
137
138
 
139
140
141
142
 
161
162
163
 
164
165
166
167
 
186
187
188
 
189
190
191
192
 
225
226
227
 
228
229
230
231
 
460
461
462
 
463
464
465
466
@@ -113,7 +113,7 @@
 MenuDescriptionMap MenuDescMap;  MenuIdCmdMap MenuIdMap;   -void AddMenuList(int idCmd, std::string name) +void AddMenuList(int idCmd, std::string const& name)  {   TDEBUG_TRACE("AddMenuList: idCmd = " << idCmd << " name = " << name);   MenuIdMap[idCmd] = MenuDescMap[name]; @@ -123,8 +123,8 @@
 {   if (MenuDescMap.empty())   { - int sz = sizeof(menuDescList) / sizeof(MenuDescription); - for (int i=0; i < sz; i++) + std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription); + for (std::size_t i=0; i < sz; i++)   {   MenuDescription md = menuDescList[i];   TDEBUG_TRACE("InitMenuMaps: adding " << md.name); @@ -136,7 +136,7 @@
 }    void InsertMenuItemWithIcon(HMENU hMenu, int indexMenu, int idCmd, - std::string menuText, std::string iconName) + std::string const& menuText, std::string const& iconName)  {   MENUITEMINFO mi;   mi.cbSize = sizeof(mi); @@ -161,7 +161,7 @@
 }    void InsertSubMenuItemWithIcon(HMENU hMenu, HMENU hSubMenu, int indexMenu, int idCmd, - std::string menuText, std::string iconName) + std::string const& menuText, std::string const& iconName)  {   MENUITEMINFO mi;   mi.cbSize = sizeof(mi); @@ -186,7 +186,7 @@
  InsertMenuItem(hMenu, indexMenu, TRUE, &mi);  }   -void InsertMenuItemByName(HMENU hMenu, std::string name, int indexMenu, +void InsertMenuItemByName(HMENU hMenu, std::string const& name, int indexMenu,   int idCmd, int idCmdFirst)  {   TDEBUG_TRACE("InsertMenuItemByName: name = " << name); @@ -225,7 +225,7 @@
  if (!bAppendItems)   return NOERROR;   - const int sz = sizeof(menuDescList) / sizeof(MenuDescription); + const std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription);   bool promoted[ sz ];   memset(&promoted, 0, sizeof(promoted));   @@ -460,7 +460,7 @@
  HANDLE tempfileHandle = CreateFileA(tempfile.c_str(), GENERIC_WRITE,   FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);   - for (int i=0; i<myFiles.size(); i++) + for (std::vector<std::string>::size_type i=0; i<myFiles.size(); i++)   {   DWORD dwWritten;   TDEBUG_TRACE("DoHgtk: temp file adding " << myFiles[i]);
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
   // Copyright (C) 2009 Benjamin Pollack  // Copyright (C) 2009 Adrian Buehlmann  //  // 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 "stdafx.h"    #include "QueryDirstate.h"  #include "dirstate.h"  #include "DirectoryStatus.h"  #include "Dirstatecache.h"  #include "Winstat.h"  #include "TortoiseUtils.h"  #include "Thgstatus.h"    #include <shlwapi.h>      class QueryState  {  public:   std::string path;   bool isdir;   std::string basedir;   std::string hgroot;     char status;   unsigned tickcount;     QueryState(): isdir(false), status(0), tickcount(0) {}  };     -bool hasHgDir(std::string path) +bool hasHgDir(std::string const& path)  { - path += "\\.hg"; - return PathIsDirectory(path.c_str()); + return PathIsDirectory((path + "\\.hg").c_str()) != 0;  }      int findHgRoot(QueryState& cur, QueryState& last, bool outdated)  {   if (cur.isdir)   {   std::string p = cur.path;   p.push_back('\\');   if (p.find(".hg\\") != std::string::npos)   {   //TDEBUG_TRACE("findHgRoot: skipping '" << cur.path << "'");   last = cur;   return 0;   }   }     if (cur.isdir && hasHgDir(cur.path))   {   cur.hgroot = cur.path;   TDEBUG_TRACE("findHgRoot(" << cur.path << "): hgroot = cur.path");   return 1;   }     cur.basedir = DirName(cur.path);     if (!outdated && !last.basedir.empty() && cur.basedir == last.basedir)   {   cur.hgroot = last.hgroot;   // TDEBUG_TRACE("findHgRoot(" << cur.path << "): hgroot = '" << cur.hgroot   // << "' (same as last.basedir)");   return 1;   }     for (std::string p = cur.basedir;;)   {   if (hasHgDir(p)) {   cur.hgroot = p;   TDEBUG_TRACE("findHgRoot(" << cur.path << "): hgroot = '" << cur.hgroot   << "' (found repo)");   return 1;   }   std::string p2 = DirName(p);   if (p2.size() == p.size())   break;   p.swap(p2);   }     TDEBUG_TRACE("findHgRoot(" << cur.path << "): NO repo found");   last = cur;   return 0;  }      int get_relpath(   const std::string& hgroot,   const std::string& path,   std::string& res  )  {   size_t offset = hgroot.size();   if (offset == 0)   return 0;     if (offset > path.size())   return 0;     if (path[offset] == '\\')   offset++;     const char* relpathptr = path.c_str() + offset;     res = relpathptr;   return 1;  }      int HgQueryDirstate(   const std::string& path, const char& filterStatus, char& outStatus)  {   static QueryState last;     if (path.empty())   return 0;     QueryState cur;     cur.path = path;   cur.tickcount = GetTickCount();     const bool outdated = cur.tickcount - last.tickcount > 2000;     if (!outdated && last.path == path)   {   outStatus = last.status;   return 1;   }     if (PathIsRoot(path.c_str()))   {   last = cur;   return 0;   }     cur.isdir = PathIsDirectory(cur.path.c_str());     if (findHgRoot(cur, last, outdated) == 0)   return 0;     size_t offset = cur.hgroot.length();     if (offset == 0)   {   last = cur;   return 0;   }     if (path[offset] == '\\')   offset++;   const char* relpathptr = path.c_str() + offset;     std::string relpath = relpathptr;     for (size_t i = 0; i < relpath.size(); ++i)   {   if (relpath[i] == '\\')   relpath[i] = '/';   }     if (cur.isdir)   {   if (!relpath.empty())   {   Dirstate* pds2 = Dirstatecache::get(cur.hgroot, cur.basedir);   if (pds2 && !pds2->root().getdir(relpath))   return 0; // unknown dir -> no icon   }     DirectoryStatus* pds = DirectoryStatus::get(cur.hgroot);   outStatus = (pds ? pds->status(relpath) : '?');   }   else   {   Dirstate* pds = Dirstatecache::get(cur.hgroot, cur.basedir);   if (!pds)   {   TDEBUG_TRACE("HgQueryDirstate: Dirstatecache::get("   << cur.hgroot << ") returns no Dirstate");   last = cur;   return 0;   }     if (filterStatus == 'A' && pds->num_added() == 0) {   last = cur;   return 0;   }     const Direntry* e = pds->root().get(relpath);   if (!e) {   last = cur;   return 0;   }     Winstat stat;   if (0 != stat.lstat(path.c_str())) {   TDEBUG_TRACE("HgQueryDirstate: lstat(" << path << ") failed");   last = cur;   return 0;   }     outStatus = e->status(stat);     if (outStatus == 'M')   {   DirectoryStatus* dirsst = DirectoryStatus::get(cur.hgroot);   if (dirsst)   {   std::string relbase;   if (get_relpath(cur.hgroot, cur.basedir, relbase))   {   TDEBUG_TRACE("HgQueryDirstate: relbase = '"   << relbase << "'");     char basedir_status = dirsst->status(relbase);   TDEBUG_TRACE("HgQueryDirstate: basedir_status = "   << basedir_status);     if (basedir_status != 'M')   {   Thgstatus::update(cur.hgroot);   }   }   }   }   }     cur.status = outStatus;   cur.tickcount = GetTickCount();   last = cur;   return 1;  }
 
279
280
281
282
 
283
284
285
 
279
280
281
 
282
283
284
285
@@ -279,7 +279,7 @@
  {   UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);   TDEBUG_TRACE(" hDrop uNumFiles = " << uNumFiles); - for (int i = 0; i < uNumFiles; ++i) { + for (UINT i = 0; i < uNumFiles; ++i) {   if (DragQueryFile(hDrop, i, name, MAX_PATH) > 0)   {   TDEBUG_TRACE(" DragQueryFile [" << i << "] = " << name);
 
109
110
111
112
 
113
114
115
 
109
110
111
 
112
113
114
115
@@ -109,7 +109,7 @@
     // Cuts the first token off a delimited list -std::string CutFirstToken(std::string& sList, const std::string sDelimiter) +std::string CutFirstToken(std::string& sList, const std::string& sDelimiter)  {   std::string::size_type p = sList.find(sDelimiter);   std::string sResult;
 
69
70
71
72
73
74
 
 
 
 
75
76
77
 
82
83
84
85
86
87
 
 
 
 
88
89
90
 
159
160
161
162
 
163
164
165
166
167
168
169
 
170
171
172
 
195
196
197
198
199
 
200
201
202
 
69
70
71
 
 
 
72
73
74
75
76
77
78
 
83
84
85
 
 
 
86
87
88
89
90
91
92
 
161
162
163
 
164
165
166
167
168
169
170
 
171
172
173
174
 
197
198
199
 
 
200
201
202
203
@@ -69,9 +69,10 @@
  TCHAR lpszValue[MAX_PATH] = "";   LONG lpcbLonger = MAX_PATH * sizeof(TCHAR);   - RegQueryValue(key, regname, lpszValue, &lpcbLonger); - std::string result(reinterpret_cast<char*>(lpszValue)); - return result; + if (RegQueryValue(key, regname, lpszValue, &lpcbLonger) != ERROR_SUCCESS) + return ""; + + return lpszValue;  }     @@ -82,9 +83,10 @@
  TCHAR lpszValue[MAX_PATH] = "";   LONG lpcbLonger = MAX_PATH * sizeof(TCHAR);   - RegQueryValue(key, regname, lpszValue, &lpcbLonger); - std::string result(reinterpret_cast<char*>(lpszValue)); - return result; + if (RegQueryValue(key, regname, lpszValue, &lpcbLonger) != ERROR_SUCCESS) + return ""; + + return lpszValue;  }     @@ -159,14 +161,14 @@
  }   else if (GetTempFileName(tempDir, prefix, 0, tempFile) != 0)   { - return std::string(tempFile); + return tempFile;   }   else   {   TDEBUG_TRACE("GetTemporaryFile: Failed to get temporary file");   }   - return std::string(); + return "";  }     @@ -195,8 +197,7 @@
  if (filename.empty())   return filename;   std::string::size_type pos = filename.find_last_of("\\"); - std::string myfilename = filename.substr(pos+1); - return myfilename; + return filename.substr(pos+1);  }    HICON GetTortoiseIcon(const std::string& iconname)