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

shellext: new Direntry::read()

Changeset 5cda5fda8327

Parent e03b889d02bb

by Adrian Buehlmann

Changes to 4 files · Browse files at 5cda5fda8327 Showing diff from parent e03b889d02bb Diff from another changeset...

 
251
252
253
254
 
255
256
257
 
251
252
253
 
254
255
256
257
@@ -251,7 +251,7 @@
  }   printf(   "%c %6o %10u %-24s %s\n", - i->state, i->mode, i->length, s.c_str(), p.c_str() + i->state, i->mode, i->size, s.c_str(), p.c_str()   );   }  }
 
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
 
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
@@ -42,6 +42,31 @@
 }     +int Direntry::read(FILE* f, std::vector<char>& relpath) +{ + if (fread(&state, sizeof(state), 1, f) != 1) + return 0; + + unsigned length = 0; + + fread(&mode, sizeof(mode), 1, f); + fread(&size, sizeof(size), 1, f); + fread(&mtime, sizeof(mtime), 1, f); + fread(&length, sizeof(length), 1, f); + + mode = ntohl(mode); + size = ntohl(size); + mtime = ntohl(mtime); + length = ntohl(length); + + relpath.resize(length + 1, 0); + fread(&relpath[0], sizeof(char), length, f); + relpath[length] = 0; + + return 1; +} + +  char Direntry::status(const thg_stat& stat) const  {   switch (this->state)
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
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
   // 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/>.    #ifndef DIRENTRY_H  #define DIRENTRY_H   +#include <vector> +    struct thg_stat  {   unsigned size;   unsigned mtime;   bool isdir;  };    int lstat(const char* file, thg_stat& rstat);     -struct Direntry +class Direntry  { +public:   unsigned char state;   unsigned mode;   unsigned size;   unsigned mtime; - unsigned length;     std::string name;   + int read(FILE* f, std::vector<char>& relpath);   char status(const thg_stat& stat) const; + +private: + static uint32_t ntohl(uint32_t x) + { + return ((x & 0x000000ffUL) << 24) | + ((x & 0x0000ff00UL) << 8) | + ((x & 0x00ff0000UL) >> 8) | + ((x & 0xff000000UL) >> 24); + }  };    #endif
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
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
 
55
56
57
 
 
 
 
 
 
 
 
58
59
60
 
73
74
75
 
 
 
 
76
77
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80
81
 
82
83
84
85
@@ -55,14 +55,6 @@
 private:   Dirstate()   : root_(0, ""), num_added_(0), num_entries_(0) {} - - static uint32_t ntohl(uint32_t x) - { - return ((x & 0x000000ffUL) << 24) | - ((x & 0x0000ff00UL) << 8) | - ((x & 0x00ff0000UL) >> 8) | - ((x & 0xff000000UL) >> 24); - }  };     @@ -81,29 +73,13 @@
  fread(&pd->parent2, sizeof(char), HASH_LENGTH, f);     Direntry e; - - std::vector<char> temp(MAX_PATH+10, 0); - - while (fread(&e.state, sizeof(e.state), 1, f) == 1) + std::vector<char> relpath(MAX_PATH + 10, 0); + while (e.read(f, relpath))   { - fread(&e.mode, sizeof(e.mode), 1, f); - fread(&e.size, sizeof(e.size), 1, f); - fread(&e.mtime, sizeof(e.mtime), 1, f); - fread(&e.length, sizeof(e.length), 1, f); - - e.mode = ntohl(e.mode); - e.size = ntohl(e.size); - e.mtime = ntohl(e.mtime); - e.length = ntohl(e.length); - - temp.resize(e.length+1, 0); - fread(&temp[0], sizeof(char), e.length, f); - temp[e.length] = 0; -   if (e.state == 'a')   ++pd->num_added_;   - pd->add(&temp[0], e); + pd->add(&relpath[0], e);   }     fclose(f);