Skip to content

Commit 91f1751

Browse files
committed
revision.c: add show_object_with_name() helper function
There are two copies of traverse_commit_list callback that show the object name followed by pathname the object was found, to produce output similar to "rev-list --objects". Unify them. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f25b62 commit 91f1751

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

builtin/rev-list.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,8 @@ static void finish_object(struct object *obj, const struct name_path *path, cons
176176

177177
static void show_object(struct object *obj, const struct name_path *path, const char *component)
178178
{
179-
char *name = path_name(path, component);
180-
/* An object with name "foo\n0000000..." can be used to
181-
* confuse downstream "git pack-objects" very badly.
182-
*/
183-
const char *ep = strchr(name, '\n');
184-
185179
finish_object(obj, path, component);
186-
if (ep) {
187-
printf("%s %.*s\n", sha1_to_hex(obj->sha1),
188-
(int) (ep - name),
189-
name);
190-
}
191-
else
192-
printf("%s %s\n", sha1_to_hex(obj->sha1), name);
193-
free(name);
180+
show_object_with_name(stdout, obj, path, component);
194181
}
195182

196183
static void show_edge(struct commit *commit)

revision.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ char *path_name(const struct name_path *path, const char *name)
4040
return n;
4141
}
4242

43+
void show_object_with_name(FILE *out, struct object *obj, const struct name_path *path, const char *component)
44+
{
45+
char *name = path_name(path, component);
46+
const char *ep = strchr(name, '\n');
47+
48+
/*
49+
* An object with name "foo\n0000000..." can be used to
50+
* confuse downstream "git pack-objects" very badly.
51+
*/
52+
if (ep) {
53+
fprintf(out, "%s %.*s\n", sha1_to_hex(obj->sha1),
54+
(int) (ep - name),
55+
name);
56+
}
57+
else
58+
fprintf(out, "%s %s\n", sha1_to_hex(obj->sha1), name);
59+
free(name);
60+
}
61+
4362
void add_object(struct object *obj,
4463
struct object_array *p,
4564
struct name_path *path,

revision.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ struct name_path {
185185

186186
char *path_name(const struct name_path *path, const char *name);
187187

188+
extern void show_object_with_name(FILE *, struct object *, const struct name_path *, const char *);
189+
188190
extern void add_object(struct object *obj,
189191
struct object_array *p,
190192
struct name_path *path,

upload-pack.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,7 @@ static void show_commit(struct commit *commit, void *data)
8585

8686
static void show_object(struct object *obj, const struct name_path *path, const char *component)
8787
{
88-
/* An object with name "foo\n0000000..." can be used to
89-
* confuse downstream git-pack-objects very badly.
90-
*/
91-
const char *name = path_name(path, component);
92-
const char *ep = strchr(name, '\n');
93-
if (ep) {
94-
fprintf(pack_pipe, "%s %.*s\n", sha1_to_hex(obj->sha1),
95-
(int) (ep - name),
96-
name);
97-
}
98-
else
99-
fprintf(pack_pipe, "%s %s\n",
100-
sha1_to_hex(obj->sha1), name);
101-
free((char *)name);
88+
show_object_with_name(pack_pipe, obj, path, component);
10289
}
10390

10491
static void show_edge(struct commit *commit)

0 commit comments

Comments
 (0)