git-access: use the new format_string helpers

It may be a bit less efficient to use a printf-style interface rather
than the explicit malloc and memcpy, but the code ends up simpler and
more readable.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2015-01-24 12:56:34 +12:00 committed by Dirk Hohndel
parent e287590e4b
commit b770d0a6b7

View file

@ -49,19 +49,15 @@ struct git_repository *is_git_repository(const char *filename, const char **bran
* to generate proper error messages. * to generate proper error messages.
*/ */
*branchp = filename; *branchp = filename;
loc = malloc(flen+1); loc = format_string("%.*s", flen, filename);
if (!loc) if (!loc)
return dummy_git_repository; return dummy_git_repository;
memcpy(loc, filename, flen);
loc[flen] = 0;
branch = malloc(blen+1); branch = format_string("%.*s", blen, filename+flen+1);
if (!branch) { if (!branch) {
free(loc); free(loc);
return dummy_git_repository; return dummy_git_repository;
} }
memcpy(branch, filename+flen+1, blen);
branch[blen] = 0;
if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) { if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) {
free(loc); free(loc);