Skip to content

Commit 4a3348a

Browse files
lucasoshirogitster
authored andcommitted
repo: factor out field printing to dedicated function
Move the field printing in git-repo-info to a new function called `print_field`, allowing it to be called by functions other than `print_fields`. Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4253630 commit 4a3348a

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

builtin/repo.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ static get_value_fn *get_value_fn_for_key(const char *key)
7777
return found ? found->get_value : NULL;
7878
}
7979

80+
static void print_field(enum output_format format, const char *key,
81+
struct strbuf *valbuf, struct strbuf *quotbuf)
82+
{
83+
strbuf_reset(quotbuf);
84+
85+
switch (format) {
86+
case FORMAT_KEYVALUE:
87+
quote_c_style(valbuf->buf, quotbuf, NULL, 0);
88+
printf("%s=%s\n", key, quotbuf->buf);
89+
break;
90+
case FORMAT_NUL_TERMINATED:
91+
printf("%s\n%s%c", key, valbuf->buf, '\0');
92+
break;
93+
default:
94+
BUG("not a valid output format: %d", format);
95+
}
96+
}
97+
8098
static int print_fields(int argc, const char **argv,
8199
struct repository *repo,
82100
enum output_format format)
@@ -97,21 +115,8 @@ static int print_fields(int argc, const char **argv,
97115
}
98116

99117
strbuf_reset(&valbuf);
100-
strbuf_reset(&quotbuf);
101-
102118
get_value(repo, &valbuf);
103-
104-
switch (format) {
105-
case FORMAT_KEYVALUE:
106-
quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
107-
printf("%s=%s\n", key, quotbuf.buf);
108-
break;
109-
case FORMAT_NUL_TERMINATED:
110-
printf("%s\n%s%c", key, valbuf.buf, '\0');
111-
break;
112-
default:
113-
BUG("not a valid output format: %d", format);
114-
}
119+
print_field(format, key, &valbuf, &quotbuf);
115120
}
116121

117122
strbuf_release(&valbuf);

0 commit comments

Comments
 (0)