rev-list --objects: use full pathname to help hashing.
This helps to group the same files from different revs together, while spreading files with the same basename in different directories, to help pack-object. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 22, 2006 at 22:10 UTC
e646de0d14bac20ef6e156c1742b9e62fb0b9020
1 file changed
+56
-13
rev-list.c
+56
-13
@@ -63,6 +63,36 @@ static int no_merges = 0;
63
static const char **paths = NULL;
64
static int remove_empty_trees = 0;
65
66
+struct name_path {
67
+ struct name_path *up;
68
+ int elem_len;
69
+ const char *elem;
70
+};
71
+
72
+static char *path_name(struct name_path *path, const char *name)
73
+{
74
+ struct name_path *p;
75
+ char *n, *m;
76
+ int nlen = strlen(name);
77
+ int len = nlen + 1;
78
+
79
+ for (p = path; p; p = p->up) {
80
+ if (p->elem_len)
81
+ len += p->elem_len + 1;
82
+ }
83
+ n = xmalloc(len);
84
+ m = n + len - (nlen + 1);
85
+ strcpy(m, name);
86
+ for (p = path; p; p = p->up) {
87
+ if (p->elem_len) {
88
+ m -= p->elem_len + 1;
89
+ memcpy(m, p->elem, p->elem_len);
90
+ m[p->elem_len] = '/';
91
+ }
92
+ }
93
+ return n;
94
+}
95
+
96
static void show_commit(struct commit *commit)
97
{
98
commit->object.flags |= SHOWN;
@@ -174,17 +204,23 @@ static int process_commit(struct commit * commit)
204
return CONTINUE;
205
}
206
177
-static struct object_list **add_object(struct object *obj, struct object_list **p, const char *name)
207
+static struct object_list **add_object(struct object *obj,
208
+ struct object_list **p,
209
+ struct name_path *path,
210
+ const char *name)
211
{
212
struct object_list *entry = xmalloc(sizeof(*entry));
213
entry->item = obj;
214
entry->next = *p;
182
- entry->name = name;
215
+ entry->name = path_name(path, name);
216
*p = entry;
217
return &entry->next;
218
}
219
187
-static struct object_list **process_blob(struct blob *blob, struct object_list **p, const char *name)
220
+static struct object_list **process_blob(struct blob *blob,
221
+ struct object_list **p,
222
+ struct name_path *path,
223
+ const char *name)
224
{
225
struct object *obj = &blob->object;
226
@@ -193,13 +229,17 @@ static struct object_list **process_blob(struct blob *blob, struct object_list *
229
if (obj->flags & (UNINTERESTING | SEEN))
230
return p;
231
obj->flags |= SEEN;
196
- return add_object(obj, p, name);
232
+ return add_object(obj, p, path, name);
233
}
234
199
-static struct object_list **process_tree(struct tree *tree, struct object_list **p, const char *name)
235
+static struct object_list **process_tree(struct tree *tree,
236
+ struct object_list **p,
237
+ struct name_path *path,
238
+ const char *name)
239
{
240
struct object *obj = &tree->object;
241
struct tree_entry_list *entry;
242
+ struct name_path me;
243
244
if (!tree_objects)
245
return p;
@@ -208,15 +248,18 @@ static struct object_list **process_tree(struct tree *tree, struct object_list *
248
if (parse_tree(tree) < 0)
249
die("bad tree object %s", sha1_to_hex(obj->sha1));
250
obj->flags |= SEEN;
211
- p = add_object(obj, p, name);
251
+ p = add_object(obj, p, path, name);
252
+ me.up = path;
253
+ me.elem = name;
254
+ me.elem_len = strlen(name);
255
entry = tree->entries;
256
tree->entries = NULL;
257
while (entry) {
258
struct tree_entry_list *next = entry->next;
259
if (entry->directory)
217
- p = process_tree(entry->item.tree, p, entry->name);
260
+ p = process_tree(entry->item.tree, p, &me, entry->name);
261
else
219
- p = process_blob(entry->item.blob, p, entry->name);
262
+ p = process_blob(entry->item.blob, p, &me, entry->name);
263
free(entry);
264
entry = next;
265
}
@@ -231,7 +274,7 @@ static void show_commit_list(struct commit_list *list)
274
while (list) {
275
struct commit *commit = pop_most_recent_commit(&list, SEEN);
276
234
- p = process_tree(commit->tree, p, "");
277
+ p = process_tree(commit->tree, p, NULL, "");
278
if (process_commit(commit) == STOP)
279
break;
280
}
@@ -242,15 +285,15 @@ static void show_commit_list(struct commit_list *list)
285
continue;
286
if (obj->type == tag_type) {
287
obj->flags |= SEEN;
245
- p = add_object(obj, p, name);
288
+ p = add_object(obj, p, NULL, name);
289
continue;
290
}
291
if (obj->type == tree_type) {
249
- p = process_tree((struct tree *)obj, p, name);
292
+ p = process_tree((struct tree *)obj, p, NULL, name);
293
continue;
294
}
295
if (obj->type == blob_type) {
253
- p = process_blob((struct blob *)obj, p, name);
296
+ p = process_blob((struct blob *)obj, p, NULL, name);
297
continue;
298
}
299
die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
@@ -674,7 +717,7 @@ static struct commit_list *limit_list(struct commit_list *list)
717
718
static void add_pending_object(struct object *obj, const char *name)
719
{
677
- add_object(obj, &pending_objects, name);
720
+ add_object(obj, &pending_objects, NULL, name);
721
}
722
723
static struct commit *get_commit_reference(const char *name, const unsigned char *sha1, unsigned int flags)