summaryrefslogtreecommitdiff
path: root/builtin/check-attr.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-01-31 11:25:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-01 21:43:02 (GMT)
commit0d4cc1b45bf063b3a46654098a9fb85f82f386a7 (patch)
treecdbec1f4d3567ad741bf47ddcce82f021a97fbdd /builtin/check-attr.c
parent1a0c8dfd89475d6bb09ddee8c019cf0ae5b3bdc2 (diff)
downloadgit-0d4cc1b45bf063b3a46654098a9fb85f82f386a7.zip
git-0d4cc1b45bf063b3a46654098a9fb85f82f386a7.tar.gz
git-0d4cc1b45bf063b3a46654098a9fb85f82f386a7.tar.bz2
give "nbuf" strbuf a more meaningful name
It's a common pattern in our code to read paths from stdin, separated either by newlines or NULs, and unquote as necessary. In each of these five cases we use "nbuf" to temporarily store the unquoted value. Let's give it the more meaningful name "unquoted", which makes it easier to understand the purpose of the variable. While we're at it, let's also static-initialize all of our strbufs. It's not wrong to call strbuf_init, but it increases the cognitive load on the reader, who might wonder "do we sometimes avoid initializing them? why?". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/check-attr.c')
-rw-r--r--builtin/check-attr.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 087325e..53a5a18 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -72,24 +72,23 @@ static void check_attr(const char *prefix, int cnt,
static void check_attr_stdin_paths(const char *prefix, int cnt,
struct git_attr_check *check)
{
- struct strbuf buf, nbuf;
+ struct strbuf buf = STRBUF_INIT;
+ struct strbuf unquoted = STRBUF_INIT;
strbuf_getline_fn getline_fn;
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
- strbuf_init(&buf, 0);
- strbuf_init(&nbuf, 0);
while (getline_fn(&buf, stdin) != EOF) {
if (!nul_term_line && buf.buf[0] == '"') {
- strbuf_reset(&nbuf);
- if (unquote_c_style(&nbuf, buf.buf, NULL))
+ strbuf_reset(&unquoted);
+ if (unquote_c_style(&unquoted, buf.buf, NULL))
die("line is badly quoted");
- strbuf_swap(&buf, &nbuf);
+ strbuf_swap(&buf, &unquoted);
}
check_attr(prefix, cnt, check, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
}
strbuf_release(&buf);
- strbuf_release(&nbuf);
+ strbuf_release(&unquoted);
}
static NORETURN void error_with_usage(const char *msg)