fsck-objects: avoid unnecessary tree_entry_list usage
Prime example of where the raw tree parser is easier for everybody. [jc: "Aieee" one-liner fix from the list applied. ] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
May 29, 2006 at 12:19 UTC
e9a95bef7f9648b3827813906582bb8a6d922d21
1 file changed
+36
-21
fsck-objects.c
+36
-21
@@ -9,6 +9,7 @@
9
#include "refs.h"
10
#include "pack.h"
11
#include "cache-tree.h"
12
+#include "tree-walk.h"
13
14
#define REACHABLE 0x0001
15
#define SEEN 0x0002
@@ -116,15 +117,15 @@ static void check_connectivity(void)
117
#define TREE_UNORDERED (-1)
118
#define TREE_HAS_DUPS (-2)
119
119
-static int verify_ordered(struct tree_entry_list *a, struct tree_entry_list *b)
120
+static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, const char *name2)
121
{
121
- int len1 = strlen(a->name);
122
- int len2 = strlen(b->name);
122
+ int len1 = strlen(name1);
123
+ int len2 = strlen(name2);
124
int len = len1 < len2 ? len1 : len2;
125
unsigned char c1, c2;
126
int cmp;
127
127
- cmp = memcmp(a->name, b->name, len);
128
+ cmp = memcmp(name1, name2, len);
129
if (cmp < 0)
130
return 0;
131
if (cmp > 0)
@@ -135,8 +136,8 @@ static int verify_ordered(struct tree_entry_list *a, struct tree_entry_list *b)
136
* Now we need to order the next one, but turn
137
* a '\0' into a '/' for a directory entry.
138
*/
138
- c1 = a->name[len];
139
- c2 = b->name[len];
139
+ c1 = name1[len];
140
+ c2 = name2[len];
141
if (!c1 && !c2)
142
/*
143
* git-write-tree used to write out a nonsense tree that has
@@ -144,9 +145,9 @@ static int verify_ordered(struct tree_entry_list *a, struct tree_entry_list *b)
145
* sure we do not have duplicate entries.
146
*/
147
return TREE_HAS_DUPS;
147
- if (!c1 && a->directory)
148
+ if (!c1 && S_ISDIR(mode1))
149
c1 = '/';
149
- if (!c2 && b->directory)
150
+ if (!c2 && S_ISDIR(mode2))
151
c2 = '/';
152
return c1 < c2 ? 0 : TREE_UNORDERED;
153
}
@@ -159,17 +160,32 @@ static int fsck_tree(struct tree *item)
160
int has_bad_modes = 0;
161
int has_dup_entries = 0;
162
int not_properly_sorted = 0;
162
- struct tree_entry_list *entry, *last;
163
+ struct tree_desc desc;
164
+ unsigned o_mode;
165
+ const char *o_name;
166
+ const unsigned char *o_sha1;
167
164
- last = NULL;
165
- for (entry = create_tree_entry_list(item); entry; entry = entry->next) {
166
- if (strchr(entry->name, '/'))
168
+ desc.buf = item->buffer;
169
+ desc.size = item->size;
170
+
171
+ o_mode = 0;
172
+ o_name = NULL;
173
+ o_sha1 = NULL;
174
+ while (desc.size) {
175
+ unsigned mode;
176
+ const char *name;
177
+ const unsigned char *sha1;
178
+
179
+ sha1 = tree_entry_extract(&desc, &name, &mode);
180
+
181
+ if (strchr(name, '/'))
182
has_full_path = 1;
168
- has_zero_pad |= entry->zeropad;
183
+ has_zero_pad |= *(char *)desc.buf == '0';
184
+ update_tree_entry(&desc);
185
170
- switch (entry->mode) {
186
+ switch (mode) {
187
/*
172
- * Standard modes..
188
+ * Standard modes..
189
*/
190
case S_IFREG | 0755:
191
case S_IFREG | 0644:
@@ -188,8 +204,8 @@ static int fsck_tree(struct tree *item)
204
has_bad_modes = 1;
205
}
206
191
- if (last) {
192
- switch (verify_ordered(last, entry)) {
207
+ if (o_name) {
208
+ switch (verify_ordered(o_mode, o_name, mode, name)) {
209
case TREE_UNORDERED:
210
not_properly_sorted = 1;
211
break;
@@ -199,13 +215,12 @@ static int fsck_tree(struct tree *item)
215
default:
216
break;
217
}
202
- free(last);
218
}
219
205
- last = entry;
220
+ o_mode = mode;
221
+ o_name = name;
222
+ o_sha1 = sha1;
223
}
207
- if (last)
208
- free(last);
224
free(item->buffer);
225
item->buffer = NULL;
226