From: Junio C Hamano Date: Mon, 13 Jul 2015 21:00:28 +0000 (-0700) Subject: Merge branch 'ss/clone-guess-dir-name-simplify' X-Git-Tag: v2.5.0-rc2~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/721f5bb8968ed6a6ec126fe28f679c17a6998e87?ds=inline;hp=-c Merge branch 'ss/clone-guess-dir-name-simplify' Code simplification. * ss/clone-guess-dir-name-simplify: clone: simplify string handling in guess_dir_name() --- 721f5bb8968ed6a6ec126fe28f679c17a6998e87 diff --combined builtin/clone.c index 00535d0178,e18839d107..a72ff7e009 --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -147,6 -147,7 +147,7 @@@ static char *get_repo_path(const char * static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) { const char *end = repo + strlen(repo), *start; + size_t len; char *dir; /* @@@ -173,20 -174,12 +174,12 @@@ /* * Strip .{bundle,git}. */ - if (is_bundle) { - if (end - start > 7 && !strncmp(end - 7, ".bundle", 7)) - end -= 7; - } else { - if (end - start > 4 && !strncmp(end - 4, ".git", 4)) - end -= 4; - } + strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len); - if (is_bare) { - struct strbuf result = STRBUF_INIT; - strbuf_addf(&result, "%.*s.git", (int)(end - start), start); - dir = strbuf_detach(&result, NULL); - } else - dir = xstrndup(start, end - start); + if (is_bare) + dir = xstrfmt("%.*s.git", (int)len, start); + else + dir = xstrndup(start, len); /* * Replace sequences of 'control' characters and whitespace * with one ascii space, remove leading and trailing spaces. @@@ -284,17 -277,16 +277,17 @@@ static void copy_alternates(struct strb struct strbuf line = STRBUF_INIT; while (strbuf_getline(&line, in, '\n') != EOF) { - char *abs_path, abs_buf[PATH_MAX]; + char *abs_path; if (!line.len || line.buf[0] == '#') continue; if (is_absolute_path(line.buf)) { add_to_alternates_file(line.buf); continue; } - abs_path = mkpath("%s/objects/%s", src_repo, line.buf); - normalize_path_copy(abs_buf, abs_path); - add_to_alternates_file(abs_buf); + abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf); + normalize_path_copy(abs_path, abs_path); + add_to_alternates_file(abs_path); + free(abs_path); } strbuf_release(&line); fclose(in);