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

DirectoryStatus.cpp: do cache failed reads

Without this, read() is needlessly retried like mad when
navigating inside repos that don't have a thgstatus file
anyway.

Changeset 80264ebb8212

Parent 7c93021735af

by Adrian Buehlmann

Changes to one file · Browse files at 80264ebb8212 Showing diff from parent 7c93021735af 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
122
123
124
125
126
 
127
128
129
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
   // 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 "DirectoryStatus.h"      char DirectoryStatus::status(const std::string& relpath) const  {   char res = 'C';   bool added = false;   bool modified = false;     for (V::const_iterator i = v_.begin(); i != v_.end(); ++i)   {   const E& e = *i;   if (e.path_.compare(0, relpath.length(), relpath) == 0)   {   if (e.status_ == 'm' || e.status_ == 'r')   {   modified = true;   break;   }   if (e.status_ == 'a')   added = true;   }   }     if (modified)   res = 'M';   else if (added)   res = 'A';   else   res = 'C';     return res;  }      int DirectoryStatus::read(const std::string& hgroot)  {   v_.clear();     std::string p = hgroot + "\\.hg\\thgstatus";     FILE *f = fopen(p.c_str(), "rb");   if (!f)   {   TDEBUG_TRACE("DirectoryStatus::read: can't open '" << p << "'");   return 0;   }     char state;   std::vector<char> path(MAX_PATH);     DirectoryStatus::E e;     while (fread(&state, sizeof(state), 1, f) == 1)   {   e.status_ = state;     path.clear();   char t;   while (fread(&t, sizeof(t), 1, f) == 1 && t != '\n')   {   path.push_back(t);   if (path.size() > 1000)   return 0;   }   path.push_back(0);     e.path_ = &path[0];     v_.push_back(e);   }     fclose(f);     TDEBUG_TRACE("DirectoryStatus::read(" << hgroot << "): done. "   << v_.size() << " entries read");     return 1;  }      struct CacheEntry  {   std::string hgroot_;   DirectoryStatus ds_; + bool readfailed_;   unsigned tickcount_;   - CacheEntry(): tickcount_(0) {}; + CacheEntry(): readfailed_(false), tickcount_(0) {};  };      DirectoryStatus* DirectoryStatus::get(const std::string& hgroot)  {   static CacheEntry ce;     unsigned tc = GetTickCount();   - if (ce.hgroot_ == hgroot && (tc - ce.tickcount_) < 2000) - return &ce.ds_; + if (ce.hgroot_ != hgroot || (tc - ce.tickcount_) > 2000) + { + ce.hgroot_.clear(); + ce.readfailed_ = (ce.ds_.read(hgroot) == 0); + ce.hgroot_ = hgroot; + ce.tickcount_ = GetTickCount(); + }   - ce.hgroot_.clear(); - - if (ce.ds_.read(hgroot) == 0) - return 0; - - ce.hgroot_ = hgroot; - ce.tickcount_ = GetTickCount(); - return &ce.ds_; + return (ce.readfailed_ ? 0 : &ce.ds_);  }