Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2011-09-16 01:10:28 +0400
committerJunio C Hamano <gitster@pobox.com>2011-10-06 00:45:30 +0400
commit7f748c7cb2317800dcdb311c3e75a086ae0d1600 (patch)
treed8e66e18307b719c58c211c963bb9959d598415e /builtin/check-ref-format.c
parent7e9d2fe96060957d90870d2fac9b85608423e277 (diff)
Make collapse_slashes() allocate memory for its result
This will make upcoming changes a tiny bit easier. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/check-ref-format.c')
-rw-r--r--builtin/check-ref-format.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 8f416967af..989ee5cc02 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -12,25 +12,28 @@ static const char builtin_check_ref_format_usage[] =
" or: git check-ref-format --branch <branchname-shorthand>";
/*
- * Remove leading slashes and replace each run of adjacent slashes in
- * src with a single slash, and write the result to dst.
+ * Return a copy of refname but with leading slashes removed and runs
+ * of adjacent slashes replaced with single slashes.
*
* This function is similar to normalize_path_copy(), but stripped down
* to meet check_ref_format's simpler needs.
*/
-static void collapse_slashes(char *dst, const char *src)
+static char *collapse_slashes(const char *refname)
{
+ char *ret = xmalloc(strlen(refname) + 1);
char ch;
char prev = '/';
+ char *cp = ret;
- while ((ch = *src++) != '\0') {
+ while ((ch = *refname++) != '\0') {
if (prev == '/' && ch == prev)
continue;
- *dst++ = ch;
+ *cp++ = ch;
prev = ch;
}
- *dst = '\0';
+ *cp = '\0';
+ return ret;
}
static int check_ref_format_branch(const char *arg)
@@ -47,9 +50,7 @@ static int check_ref_format_branch(const char *arg)
static void refname_format_print(const char *arg)
{
- char *refname = xmalloc(strlen(arg) + 1);
-
- collapse_slashes(refname, arg);
+ char *refname = collapse_slashes(arg);
printf("%s\n", refname);
}