Skip to content

Commit 7d71be2

Browse files
committed
Merge branch 'lt/pack-object-memuse' into maint
* lt/pack-object-memuse: show_object(): push path_name() call further down process_{tree,blob}: show objects without buffering
2 parents a2dc04b + cf2ab91 commit 7d71be2

File tree

7 files changed

+56
-43
lines changed

7 files changed

+56
-43
lines changed

builtin-pack-objects.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,13 +1907,19 @@ static void show_commit(struct commit *commit)
19071907
commit->object.flags |= OBJECT_ADDED;
19081908
}
19091909

1910-
static void show_object(struct object_array_entry *p)
1910+
static void show_object(struct object *obj, const struct name_path *path, const char *last)
19111911
{
1912-
add_preferred_base_object(p->name);
1913-
add_object_entry(p->item->sha1, p->item->type, p->name, 0);
1914-
p->item->flags |= OBJECT_ADDED;
1915-
free((char *)p->name);
1916-
p->name = NULL;
1912+
char *name = path_name(path, last);
1913+
1914+
add_preferred_base_object(name);
1915+
add_object_entry(obj->sha1, obj->type, name, 0);
1916+
obj->flags |= OBJECT_ADDED;
1917+
1918+
/*
1919+
* We will have generated the hash from the name,
1920+
* but not saved a pointer to it - we can free it
1921+
*/
1922+
free((char *)name);
19171923
}
19181924

19191925
static void show_edge(struct commit *commit)

builtin-rev-list.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,29 @@ static void finish_commit(struct commit *commit)
168168
commit->buffer = NULL;
169169
}
170170

171-
static void finish_object(struct object_array_entry *p)
171+
static void finish_object(struct object *obj, const struct name_path *path, const char *name)
172172
{
173-
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
174-
die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
173+
if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
174+
die("missing blob object '%s'", sha1_to_hex(obj->sha1));
175175
}
176176

177-
static void show_object(struct object_array_entry *p)
177+
static void show_object(struct object *obj, const struct name_path *path, const char *component)
178178
{
179+
char *name = path_name(path, component);
179180
/* An object with name "foo\n0000000..." can be used to
180181
* confuse downstream "git pack-objects" very badly.
181182
*/
182-
const char *ep = strchr(p->name, '\n');
183+
const char *ep = strchr(name, '\n');
183184

184-
finish_object(p);
185+
finish_object(obj, path, name);
185186
if (ep) {
186-
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
187-
(int) (ep - p->name),
188-
p->name);
187+
printf("%s %.*s\n", sha1_to_hex(obj->sha1),
188+
(int) (ep - name),
189+
name);
189190
}
190191
else
191-
printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name);
192+
printf("%s %s\n", sha1_to_hex(obj->sha1), name);
193+
free(name);
192194
}
193195

194196
static void show_edge(struct commit *commit)

list-objects.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
static void process_blob(struct rev_info *revs,
1212
struct blob *blob,
13-
struct object_array *p,
13+
show_object_fn show,
1414
struct name_path *path,
1515
const char *name)
1616
{
@@ -23,7 +23,7 @@ static void process_blob(struct rev_info *revs,
2323
if (obj->flags & (UNINTERESTING | SEEN))
2424
return;
2525
obj->flags |= SEEN;
26-
add_object(obj, p, path, name);
26+
show(obj, path, name);
2727
}
2828

2929
/*
@@ -50,7 +50,7 @@ static void process_blob(struct rev_info *revs,
5050
*/
5151
static void process_gitlink(struct rev_info *revs,
5252
const unsigned char *sha1,
53-
struct object_array *p,
53+
show_object_fn show,
5454
struct name_path *path,
5555
const char *name)
5656
{
@@ -59,7 +59,7 @@ static void process_gitlink(struct rev_info *revs,
5959

6060
static void process_tree(struct rev_info *revs,
6161
struct tree *tree,
62-
struct object_array *p,
62+
show_object_fn show,
6363
struct name_path *path,
6464
const char *name)
6565
{
@@ -77,7 +77,7 @@ static void process_tree(struct rev_info *revs,
7777
if (parse_tree(tree) < 0)
7878
die("bad tree object %s", sha1_to_hex(obj->sha1));
7979
obj->flags |= SEEN;
80-
add_object(obj, p, path, name);
80+
show(obj, path, name);
8181
me.up = path;
8282
me.elem = name;
8383
me.elem_len = strlen(name);
@@ -88,14 +88,14 @@ static void process_tree(struct rev_info *revs,
8888
if (S_ISDIR(entry.mode))
8989
process_tree(revs,
9090
lookup_tree(entry.sha1),
91-
p, &me, entry.path);
91+
show, &me, entry.path);
9292
else if (S_ISGITLINK(entry.mode))
9393
process_gitlink(revs, entry.sha1,
94-
p, &me, entry.path);
94+
show, &me, entry.path);
9595
else
9696
process_blob(revs,
9797
lookup_blob(entry.sha1),
98-
p, &me, entry.path);
98+
show, &me, entry.path);
9999
}
100100
free(tree->buffer);
101101
tree->buffer = NULL;
@@ -134,16 +134,20 @@ void mark_edges_uninteresting(struct commit_list *list,
134134
}
135135
}
136136

137+
static void add_pending_tree(struct rev_info *revs, struct tree *tree)
138+
{
139+
add_pending_object(revs, &tree->object, "");
140+
}
141+
137142
void traverse_commit_list(struct rev_info *revs,
138-
void (*show_commit)(struct commit *),
139-
void (*show_object)(struct object_array_entry *))
143+
show_commit_fn show_commit,
144+
show_object_fn show_object)
140145
{
141146
int i;
142147
struct commit *commit;
143-
struct object_array objects = { 0, 0, NULL };
144148

145149
while ((commit = get_revision(revs)) != NULL) {
146-
process_tree(revs, commit->tree, &objects, NULL, "");
150+
add_pending_tree(revs, commit->tree);
147151
show_commit(commit);
148152
}
149153
for (i = 0; i < revs->pending.nr; i++) {
@@ -154,25 +158,22 @@ void traverse_commit_list(struct rev_info *revs,
154158
continue;
155159
if (obj->type == OBJ_TAG) {
156160
obj->flags |= SEEN;
157-
add_object_array(obj, name, &objects);
161+
show_object(obj, NULL, name);
158162
continue;
159163
}
160164
if (obj->type == OBJ_TREE) {
161-
process_tree(revs, (struct tree *)obj, &objects,
165+
process_tree(revs, (struct tree *)obj, show_object,
162166
NULL, name);
163167
continue;
164168
}
165169
if (obj->type == OBJ_BLOB) {
166-
process_blob(revs, (struct blob *)obj, &objects,
170+
process_blob(revs, (struct blob *)obj, show_object,
167171
NULL, name);
168172
continue;
169173
}
170174
die("unknown pending object %s (%s)",
171175
sha1_to_hex(obj->sha1), name);
172176
}
173-
for (i = 0; i < objects.nr; i++)
174-
show_object(&objects.objects[i]);
175-
free(objects.objects);
176177
if (revs->pending.nr) {
177178
free(revs->pending.objects);
178179
revs->pending.nr = 0;

list-objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define LIST_OBJECTS_H
33

44
typedef void (*show_commit_fn)(struct commit *);
5-
typedef void (*show_object_fn)(struct object_array_entry *);
5+
typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *);
66
typedef void (*show_edge_fn)(struct commit *);
77

88
void traverse_commit_list(struct rev_info *revs, show_commit_fn, show_object_fn);

revision.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
volatile show_early_output_fn_t show_early_output;
1717

18-
static char *path_name(struct name_path *path, const char *name)
18+
char *path_name(const struct name_path *path, const char *name)
1919
{
20-
struct name_path *p;
20+
const struct name_path *p;
2121
char *n, *m;
2222
int nlen = strlen(name);
2323
int len = nlen + 1;

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ struct name_path {
144144
const char *elem;
145145
};
146146

147+
char *path_name(const struct name_path *path, const char *name);
148+
147149
extern void add_object(struct object *obj,
148150
struct object_array *p,
149151
struct name_path *path,

upload-pack.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,22 @@ static void show_commit(struct commit *commit)
7878
commit->buffer = NULL;
7979
}
8080

81-
static void show_object(struct object_array_entry *p)
81+
static void show_object(struct object *obj, const struct name_path *path, const char *component)
8282
{
8383
/* An object with name "foo\n0000000..." can be used to
8484
* confuse downstream git-pack-objects very badly.
8585
*/
86-
const char *ep = strchr(p->name, '\n');
86+
const char *name = path_name(path, component);
87+
const char *ep = strchr(name, '\n');
8788
if (ep) {
88-
fprintf(pack_pipe, "%s %.*s\n", sha1_to_hex(p->item->sha1),
89-
(int) (ep - p->name),
90-
p->name);
89+
fprintf(pack_pipe, "%s %.*s\n", sha1_to_hex(obj->sha1),
90+
(int) (ep - name),
91+
name);
9192
}
9293
else
9394
fprintf(pack_pipe, "%s %s\n",
94-
sha1_to_hex(p->item->sha1), p->name);
95+
sha1_to_hex(obj->sha1), name);
96+
free((char *)name);
9597
}
9698

9799
static void show_edge(struct commit *commit)

0 commit comments

Comments
 (0)