summaryrefslogtreecommitdiff
path: root/builtin/hash-object.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2016-01-31 06:25:26 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-02-01 13:43:02 -0800
commit0d4cc1b45bf063b3a46654098a9fb85f82f386a7 (patch)
treecdbec1f4d3567ad741bf47ddcce82f021a97fbdd /builtin/hash-object.c
parentstrbuf: give strbuf_getline() to the "most text friendly" variant (diff)
downloadtgif-0d4cc1b45bf063b3a46654098a9fb85f82f386a7.tar.xz
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/hash-object.c')
-rw-r--r--builtin/hash-object.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 3bc5ec1d21..d3cb4e5345 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -58,20 +58,21 @@ static void hash_object(const char *path, const char *type, const char *vpath,
static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
int literally)
{
- struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ struct strbuf unquoted = STRBUF_INIT;
while (strbuf_getline_lf(&buf, stdin) != EOF) {
if (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);
}
hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags,
literally);
}
strbuf_release(&buf);
- strbuf_release(&nbuf);
+ strbuf_release(&unquoted);
}
int cmd_hash_object(int argc, const char **argv, const char *prefix)