Skip to content

Commit 9824a38

Browse files
committed
Merge branch 'lt/pack-object-memuse'
* lt/pack-object-memuse: show_object(): push path_name() call further down process_{tree,blob}: show objects without buffering Conflicts: builtin-pack-objects.c builtin-rev-list.c list-objects.c list-objects.h upload-pack.c
2 parents 5758b25 + cf2ab91 commit 9824a38

File tree

7 files changed

+54
-41
lines changed

7 files changed

+54
-41
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, void *data)
19071907
commit->object.flags |= OBJECT_ADDED;
19081908
}
19091909

1910-
static void show_object(struct object_array_entry *p, void *data)
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
@@ -156,27 +156,29 @@ static void finish_commit(struct commit *commit, void *data)
156156
commit->buffer = NULL;
157157
}
158158

159-
static void finish_object(struct object_array_entry *p, void *data)
159+
static void finish_object(struct object *obj, const struct name_path *path, const char *name)
160160
{
161-
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
162-
die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
161+
if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
162+
die("missing blob object '%s'", sha1_to_hex(obj->sha1));
163163
}
164164

165-
static void show_object(struct object_array_entry *p, void *data)
165+
static void show_object(struct object *obj, const struct name_path *path, const char *component)
166166
{
167+
char *name = path_name(path, component);
167168
/* An object with name "foo\n0000000..." can be used to
168169
* confuse downstream "git pack-objects" very badly.
169170
*/
170-
const char *ep = strchr(p->name, '\n');
171+
const char *ep = strchr(name, '\n');
171172

172-
finish_object(p, data);
173+
finish_object(obj, path, name);
173174
if (ep) {
174-
printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
175-
(int) (ep - p->name),
176-
p->name);
175+
printf("%s %.*s\n", sha1_to_hex(obj->sha1),
176+
(int) (ep - name),
177+
name);
177178
}
178179
else
179-
printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name);
180+
printf("%s %s\n", sha1_to_hex(obj->sha1), name);
181+
free(name);
180182
}
181183

182184
static void show_edge(struct commit *commit)

list-objects.c

Lines changed: 17 additions & 16 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,17 +134,21 @@ 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,
138143
show_commit_fn show_commit,
139144
show_object_fn show_object,
140145
void *data)
141146
{
142147
int i;
143148
struct commit *commit;
144-
struct object_array objects = { 0, 0, NULL };
145149

146150
while ((commit = get_revision(revs)) != NULL) {
147-
process_tree(revs, commit->tree, &objects, NULL, "");
151+
add_pending_tree(revs, commit->tree);
148152
show_commit(commit, data);
149153
}
150154
for (i = 0; i < revs->pending.nr; i++) {
@@ -155,25 +159,22 @@ void traverse_commit_list(struct rev_info *revs,
155159
continue;
156160
if (obj->type == OBJ_TAG) {
157161
obj->flags |= SEEN;
158-
add_object_array(obj, name, &objects);
162+
show_object(obj, NULL, name);
159163
continue;
160164
}
161165
if (obj->type == OBJ_TREE) {
162-
process_tree(revs, (struct tree *)obj, &objects,
166+
process_tree(revs, (struct tree *)obj, show_object,
163167
NULL, name);
164168
continue;
165169
}
166170
if (obj->type == OBJ_BLOB) {
167-
process_blob(revs, (struct blob *)obj, &objects,
171+
process_blob(revs, (struct blob *)obj, show_object,
168172
NULL, name);
169173
continue;
170174
}
171175
die("unknown pending object %s (%s)",
172176
sha1_to_hex(obj->sha1), name);
173177
}
174-
for (i = 0; i < objects.nr; i++)
175-
show_object(&objects.objects[i], data);
176-
free(objects.objects);
177178
if (revs->pending.nr) {
178179
free(revs->pending.objects);
179180
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 *, void *);
5-
typedef void (*show_object_fn)(struct object_array_entry *, void *);
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 *, show_commit_fn, show_object_fn, void *);

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
@@ -146,6 +146,8 @@ struct name_path {
146146
const char *elem;
147147
};
148148

149+
char *path_name(const struct name_path *path, const char *name);
150+
149151
extern void add_object(struct object *obj,
150152
struct object_array *p,
151153
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, void *data)
7878
commit->buffer = NULL;
7979
}
8080

81-
static void show_object(struct object_array_entry *p, void *data)
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)