Changeset 5cda5fda8327…
Parent e03b889d02bb…
by
Changes to 4 files · Browse files at 5cda5fda8327 Showing diff from parent e03b889d02bb Diff from another changeset...
@@ -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,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)
|
@@ -18,6 +18,8 @@ #ifndef DIRENTRY_H
#define DIRENTRY_H
+#include <vector>
+
struct thg_stat
{
@@ -29,17 +31,27 @@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,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);
|
Loading...