Skip to content

Commit 8eee9f9

Browse files
peffgitster
authored andcommitted
show_object_with_name: simplify by using path_name()
When "git rev-list" shows an object with its associated path name, it does so by walking the name_path linked list and printing each component (stopping at any embedded NULs or newlines). We'd like to eventually get rid of name_path entirely in favor of a single buffer, and dropping this custom printing code is part of that. As a first step, let's use path_name() to format the list into a single buffer, and print that. This is strictly less efficient than the original, but it's a temporary step in the refactoring; our end game will be to get the fully formatted name in the first place. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c6bd2a1 commit 8eee9f9

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

revision.c

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,18 @@ char *path_name(const struct name_path *path, const char *name)
4545
return n;
4646
}
4747

48-
static int show_path_component_truncated(FILE *out, const char *name, int len)
49-
{
50-
int cnt;
51-
for (cnt = 0; cnt < len; cnt++) {
52-
int ch = name[cnt];
53-
if (!ch || ch == '\n')
54-
return -1;
55-
fputc(ch, out);
56-
}
57-
return len;
58-
}
59-
60-
static int show_path_truncated(FILE *out, const struct name_path *path)
61-
{
62-
int emitted, ours;
63-
64-
if (!path)
65-
return 0;
66-
emitted = show_path_truncated(out, path->up);
67-
if (emitted < 0)
68-
return emitted;
69-
if (emitted)
70-
fputc('/', out);
71-
ours = show_path_component_truncated(out, path->elem, path->elem_len);
72-
if (ours < 0)
73-
return ours;
74-
return ours || emitted;
75-
}
76-
7748
void show_object_with_name(FILE *out, struct object *obj,
7849
const struct name_path *path, const char *component)
7950
{
80-
struct name_path leaf;
81-
leaf.up = (struct name_path *)path;
82-
leaf.elem = component;
83-
leaf.elem_len = strlen(component);
51+
char *name = path_name(path, component);
52+
char *p;
8453

8554
fprintf(out, "%s ", sha1_to_hex(obj->sha1));
86-
show_path_truncated(out, &leaf);
55+
for (p = name; *p && *p != '\n'; p++)
56+
fputc(*p, out);
8757
fputc('\n', out);
58+
59+
free(name);
8860
}
8961

9062
static void mark_blob_uninteresting(struct blob *blob)

0 commit comments

Comments
 (0)