Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: use ATL strings and collections, part 3

Changeset caf9be1e996d

Parent 9d4d5bcf994e

by David Golub

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

 
21
22
23
24
 
25
26
27
 
38
39
40
41
42
43
 
 
 
44
45
 
46
47
48
 
21
22
23
 
24
25
26
27
 
38
39
40
 
 
 
41
42
43
44
 
45
46
47
48
@@ -21,7 +21,7 @@
 #include "Winstat.h"     -int Direntry::read(FILE* f, std::vector<char>& relpath) +int Direntry::read(FILE* f, CString& relpath)  {   if (fread(&state, sizeof(state), 1, f) != 1)   return 0; @@ -38,11 +38,11 @@
  mtime = ntohl(mtime);   length = ntohl(length);   - relpath.resize(length + 1, 0); - fread(&relpath[0], sizeof(char), length, f); - relpath[length] = 0; + LPSTR lpszBuf = relpath.GetBuffer(length); + fread(lpszBuf, sizeof(char), length, f); + relpath.ReleaseBuffer(length);   - ::CharLowerBuff(&relpath[0], length); + relpath = relpath.MakeLower();     return 1;  }
 
18
19
20
21
22
23
24
25
 
37
38
39
40
 
41
42
43
 
18
19
20
 
 
21
22
23
 
35
36
37
 
38
39
40
41
@@ -18,8 +18,6 @@
 #ifndef DIRENTRY_H  #define DIRENTRY_H   -#include <vector> -  // Visual Studio has UINT32 instead of uint32_t  #ifndef uint32_t  #define uint32_t UINT32 @@ -37,7 +35,7 @@
    CString name;   - int read(FILE* f, std::vector<char>& relpath); + int read(FILE* f, CString& relpath);   char status(const Winstat& stat) const;     bool unset() const {
 
22
23
24
25
 
26
27
 
28
29
30
 
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
 
114
115
116
117
 
118
119
120
121
122
123
124
 
125
126
127
 
132
133
134
135
 
136
137
138
 
 
139
140
141
142
 
143
144
145
 
 
146
147
148
 
154
155
156
157
 
158
159
160
 
165
166
167
168
 
 
169
170
 
 
171
172
173
174
 
 
175
176
177
 
22
23
24
 
25
26
 
27
28
29
30
 
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
 
113
114
115
 
116
117
118
119
120
121
122
 
123
124
125
126
 
131
132
133
 
134
135
 
 
136
137
138
139
140
 
141
142
 
 
143
144
145
146
147
 
153
154
155
 
156
157
158
159
 
164
165
166
 
167
168
169
 
170
171
172
 
 
 
173
174
175
176
177
@@ -22,9 +22,9 @@
 #include "Thgstatus.h"  #include "Winstat.h"   -std::list<Dirstatecache::E>& Dirstatecache::cache() +CAtlList<Dirstatecache::E>& Dirstatecache::cache()  { - static std::list<Dirstatecache::E> c; + static CAtlList<Dirstatecache::E> c;   return c;  }   @@ -34,75 +34,74 @@
 {   unset = false;   - typedef std::list<E>::iterator Iter; - - Iter iter = cache().begin(); - for (;iter != cache().end(); ++iter) + POSITION position = cache().GetHeadPosition(); + while (position != NULL)   { - if (hgroot == iter->hgroot && usekbfiles == iter->usekbfiles) + E& rItem = cache().GetAt(position); + if (hgroot == rItem.hgroot && usekbfiles == rItem.usekbfiles)   break; + cache().GetNext(position);   }     Winstat stat; - std::string path = hgroot + (usekbfiles ? "\\.hg\\kilnbfiles\\dirstate" + CString path = hgroot + (usekbfiles ? "\\.hg\\kilnbfiles\\dirstate"   : "\\.hg\\dirstate");     unsigned tc = GetTickCount();   bool new_stat = false;   - if (iter == cache().end()) + if (position == NULL)   { - if (stat.lstat(path.c_str(), true) != 0) + if (stat.lstat(path, true) != 0)   { - ATLTRACE("Dirstatecache::get: lstat('%s') failed\n", path.c_str()); + ATLTRACE("Dirstatecache::get: lstat('%s') failed\n", (LPCTSTR)path);   return 0;   } - ATLTRACE("Dirstatecache::get: lstat('%s') ok\n", path.c_str()); + ATLTRACE("Dirstatecache::get: lstat('%s') ok\n", (LPCTSTR)path);   new_stat = true;   - if (cache().size() >= 10) + if (cache().GetCount() >= 10)   { - ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)cache().back().hgroot); - delete cache().back().dstate; - cache().back().dstate = 0; - cache().pop_back(); + E e = cache().RemoveTail(); + ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)e.hgroot); + delete e.dstate;   }     E e;   e.hgroot = hgroot;   e.usekbfiles = usekbfiles; - cache().push_front(e); - iter = cache().begin(); - iter->tickcount = tc; + e.tickcount = tc; + cache().AddHead(e); + position = cache().GetHeadPosition();   }   - if (!new_stat && tc - iter->tickcount > 500) + E& rItem = cache().GetAt(position); + if (!new_stat && tc - rItem.tickcount > 500)   { - if (0 != stat.lstat(path.c_str(), true)) + if (0 != stat.lstat(path, true))   { - ATLTRACE("Dirstatecache::get: lstat('%s') failed\n", path.c_str()); - ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)iter->hgroot); - delete iter->dstate; - iter->dstate = 0; - cache().erase(iter); + ATLTRACE("Dirstatecache::get: lstat('%s') failed\n", (LPCTSTR)path); + ATLTRACE("Dirstatecache::get: dropping '%s'\n", (LPCTSTR)rItem.hgroot); + delete rItem.dstate; + cache().RemoveAt(position);   return 0;   } - iter->tickcount = tc; - ATLTRACE("Dirstatecache::get: lstat('%s') ok\n", path.c_str()); + rItem.tickcount = tc; + ATLTRACE("Dirstatecache::get: lstat('%s') ok\n", (LPCTSTR)path);   new_stat = true;   }   - if (iter->dstate) + if (rItem.dstate)   { - unset = iter->unset; + unset = rItem.unset;     if (!new_stat) - return iter->dstate; + return rItem.dstate;   - if (iter->dstate_mtime == stat.mtime - && iter->dstate_size == stat.size) + if (rItem.dstate_mtime == stat.mtime + && rItem.dstate_size == stat.size)   { - return iter->dstate; + return rItem.dstate;   }     ATLTRACE("Dirstatecache::get: refreshing '%s'\n", hgroot); @@ -114,14 +113,14 @@
    unset = false;   unsigned tc0 = GetTickCount(); - std::auto_ptr<Dirstate> ds = Dirstate::read(path, unset); + CAutoPtr<Dirstate> ds = Dirstate::read(path, unset);   unsigned tc1 = GetTickCount();     bool request_thgstatus_update = true;     if (unset)   { - if (iter->unset) + if (rItem.unset)   {   ATLTRACE("Dirstatecache::get: **** old and new have unset entries\n");   request_thgstatus_update = false; @@ -132,17 +131,17 @@
  }   }   - iter->unset = unset; + rItem.unset = unset;   - delete iter->dstate; - iter->dstate = ds.release(); + delete rItem.dstate; + rItem.dstate = ds.Detach();     unsigned delta = tc1 - tc0;   ATLTRACE("Dirstatecache::get: read done in %d ticks, %d repos in cache\n", - delta, cache().size()); + delta, cache().GetCount());   - iter->dstate_mtime = stat.mtime; - iter->dstate_size = stat.size; + rItem.dstate_mtime = stat.mtime; + rItem.dstate_size = stat.size;     if (request_thgstatus_update)   { @@ -154,7 +153,7 @@
  ATLTRACE("Dirstatecache::get: omitting Thgstatus::update\n");   }   - return iter->dstate; + return rItem.dstate;  }     @@ -165,13 +164,14 @@
  if (hgroot.IsEmpty())   return;   - for (Iter i = cache().begin(); i != cache().end(); ++i) + POSITION position = cache().GetHeadPosition(); + while (position != NULL)   { - if (hgroot == i->hgroot && usekbfiles == i->usekbfiles) + E& rItem = cache().GetAt(position); + if (hgroot == rItem.hgroot && usekbfiles == rItem.usekbfiles)   { - delete i->dstate; - i->dstate = 0; - cache().erase(i); + delete rItem.dstate; + cache().RemoveAt(position);   ATLTRACE("Dirstatecache::invalidate('%s')\n", (LPCTSTR)hgroot);   break;   }
 
18
19
20
21
22
23
24
 
46
47
48
49
 
50
51
52
 
18
19
20
 
21
22
23
 
45
46
47
 
48
49
50
51
@@ -18,7 +18,6 @@
 #ifndef _DIRSTATECACHE_H  #define _DIRSTATECACHE_H   -#include <string>  #include <list>    class Dirstate; @@ -46,7 +45,7 @@
  {}   };   - static std::list<E>& cache(); + static CAtlList<E>& cache();    public:   static Dirstate* get(const CString& hgroot, const CString& cwd, bool& unset,
 
21
22
23
24
 
25
26
27
28
 
29
30
31
32
 
 
33
34
35
 
36
37
38
39
40
41
 
42
43
44
 
47
48
49
50
 
51
52
53
 
74
75
76
77
78
 
 
79
80
81
 
21
22
23
 
24
25
26
27
 
28
29
30
 
 
31
32
33
34
 
35
36
37
38
39
40
 
41
42
43
44
 
47
48
49
 
50
51
52
53
 
74
75
76
 
 
77
78
79
80
81
@@ -21,24 +21,24 @@
 #include "TortoiseUtils.h"     -std::auto_ptr<Dirstate> Dirstate::read(const std::string& path, bool& unset) +CAutoPtr<Dirstate> Dirstate::read(const CString& path, bool& unset)  {   unset = false;   - FILE *f = fopenReadRenameAllowed(path.c_str()); + FILE *f = fopenReadRenameAllowed(path);   if (!f)   { - ATLTRACE("Dirstate::read: can't open '%s'\n", path.c_str()); - return std::auto_ptr<Dirstate>(0); + ATLTRACE("Dirstate::read: can't open '%s'\n", (LPCTSTR)path); + return CAutoPtr<Dirstate>(NULL);   }   - std::auto_ptr<Dirstate> pd(new Dirstate()); + CAutoPtr<Dirstate> pd(new Dirstate());     fread(&pd->parent1, sizeof(char), HASH_LENGTH, f);   fread(&pd->parent2, sizeof(char), HASH_LENGTH, f);     Direntry e; - std::vector<char> relpath(MAX_PATH + 10, 0); + CString relpath;   while (e.read(f, relpath))   {   if (e.unset()) @@ -47,7 +47,7 @@
  if (e.state == 'a')   ++pd->num_added_;   - pd->add(&relpath[0], e); + pd->add(relpath, e);   }     fclose(f); @@ -74,8 +74,8 @@
 void testread()  {   bool unset; - std::auto_ptr<Dirstate> pd = Dirstate::read(".hg/dirstate", unset); - if (!pd.get()) { + CAutoPtr<Dirstate> pd = Dirstate::read(".hg/dirstate", unset); + if ((Dirstate*)pd == NULL) {   printf("error: could not read .hg/dirstate\n");   return;   }
 
20
21
22
23
24
25
26
27
28
 
36
37
38
39
 
40
41
42
 
20
21
22
 
 
 
23
24
25
 
33
34
35
 
36
37
38
39
@@ -20,9 +20,6 @@
   #include "Directory.h"   -#include <string> - -  #define HASH_LENGTH 20    class Dirstate @@ -36,7 +33,7 @@
  char parent1[HASH_LENGTH];   char parent2[HASH_LENGTH];   - static std::auto_ptr<Dirstate> read(const std::string& path, bool& unset); + static CAutoPtr<Dirstate> read(const CString& path, bool& unset);     Directory& root() { return root_; }