mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
e287590e4b
commit
b770d0a6b7
1 changed files with 2 additions and 6 deletions
|
@ -49,19 +49,15 @@ struct git_repository *is_git_repository(const char *filename, const char **bran
|
|||
* to generate proper error messages.
|
||||
*/
|
||||
*branchp = filename;
|
||||
loc = malloc(flen+1);
|
||||
loc = format_string("%.*s", flen, filename);
|
||||
if (!loc)
|
||||
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) {
|
||||
free(loc);
|
||||
return dummy_git_repository;
|
||||
}
|
||||
memcpy(branch, filename+flen+1, blen);
|
||||
branch[blen] = 0;
|
||||
|
||||
if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
||||
free(loc);
|
||||
|
|
Loading…
Add table
Reference in a new issue