summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7e9d2fe)
raw | patch | inline | side by side (parent: 7e9d2fe)
author | Michael Haggerty <mhagger@alum.mit.edu> | |
Thu, 15 Sep 2011 21:10:28 +0000 (23:10 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 5 Oct 2011 20:45:30 +0000 (13:45 -0700) |
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>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/check-ref-format.c | patch | blob | history |
index 8f416967afd8cae2bfc40ba23f50c5e8c91d483e..989ee5cc023d55ee42aa2d1a316032f494a836bf 100644 (file)
" 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)
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);
}