diff options
author | Jeff King <peff@peff.net> | 2017-03-20 21:22:28 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-03-21 11:12:53 -0700 |
commit | 116fb64e439d3744d0f244a51d7a6d714b7703ae (patch) | |
tree | ec3e23445081ec7fbb0bc5b711b5066ad83b42f5 /builtin/hash-object.c | |
parent | 598019769cbaa38495b0c04297efa13d0f4a572e (diff) | |
download | git-116fb64e439d3744d0f244a51d7a6d714b7703ae.tar.gz |
prefix_filename: drop length parameter
This function takes the prefix as a ptr/len pair, but in
every caller the length is exactly strlen(ptr). Let's
simplify the interface and just take the string. This saves
callers specifying it (and in some cases handling a NULL
prefix).
In a handful of cases we had the length already without
calling strlen, so this is technically slower. But it's not
likely to matter (after all, if the prefix is non-empty
we'll allocate and copy it into a buffer anyway).
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.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 56df77b0c2..2ea36909d2 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -102,7 +102,6 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) OPT_END() }; int i; - int prefix_length = -1; const char *errstr = NULL; argc = parse_options(argc, argv, NULL, hash_object_options, @@ -113,9 +112,8 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) else prefix = setup_git_directory_gently(&nongit); - prefix_length = prefix ? strlen(prefix) : 0; if (vpath && prefix) - vpath = xstrdup(prefix_filename(prefix, prefix_length, vpath)); + vpath = xstrdup(prefix_filename(prefix, vpath)); git_config(git_default_config, NULL); @@ -146,9 +144,8 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; char *to_free = NULL; - if (0 <= prefix_length) - arg = to_free = - xstrdup(prefix_filename(prefix, prefix_length, arg)); + if (prefix) + arg = to_free = xstrdup(prefix_filename(prefix, arg)); hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg, flags, literally); free(to_free); |