aboutsummaryrefslogtreecommitdiffstats
path: root/core/git-access.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-01-12 22:06:16 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-01-17 21:45:48 +0200
commit2d24dceafa3b8b41d44df6438cb5f52e5de2d4da (patch)
treee7e9d37395dff02660d9aa5e3d2b13a74ca8d2dd /core/git-access.c
parentdaede13571cd528b3cb054484a626d32326d3178 (diff)
downloadsubsurface-2d24dceafa3b8b41d44df6438cb5f52e5de2d4da.tar.gz
Use format_string() in core/git_access.c
Since this helper-function exists, we might just use it. A subtle reuse of a buffer (string of second use was known to be shorter than string of first use) was replaced by a separate allocation. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/git-access.c')
-rw-r--r--core/git-access.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/core/git-access.c b/core/git-access.c
index 8a0b916e5..27cfe7831 100644
--- a/core/git-access.c
+++ b/core/git-access.c
@@ -676,7 +676,6 @@ static git_repository *create_and_push_remote(const char *localdir, const char *
{
git_repository *repo;
git_config *conf;
- int len;
char *variable_name, *merge_head;
if (verbose)
@@ -694,18 +693,15 @@ static git_repository *create_and_push_remote(const char *localdir, const char *
/* create a config so we can set the remote tracking branch */
git_repository_config(&conf, repo);
- len = sizeof("branch..remote") + strlen(branch);
- variable_name = malloc(len);
- snprintf(variable_name, len, "branch.%s.remote", branch);
+ variable_name = format_string("branch.%s.remote", branch);
git_config_set_string(conf, variable_name, "origin");
- /* we know this is shorter than the previous one, so we reuse the variable*/
- snprintf(variable_name, len, "branch.%s.merge", branch);
- len = sizeof("refs/heads/") + strlen(branch);
- merge_head = malloc(len);
- snprintf(merge_head, len, "refs/heads/%s", branch);
- git_config_set_string(conf, variable_name, merge_head);
free(variable_name);
+
+ variable_name = format_string("branch.%s.merge", branch);
+ merge_head = format_string("refs/heads/%s", branch);
+ git_config_set_string(conf, variable_name, merge_head);
free(merge_head);
+ free(variable_name);
/* finally create an empty commit and push it to the remote */
if (do_git_save(repo, branch, remote, false, true))
@@ -745,10 +741,8 @@ static git_repository *create_local_repo(const char *localdir, const char *remot
msg = giterr_last()->message;
fprintf(stderr, "error message was %s\n", msg);
}
- int len = sizeof("reference 'refs/remotes/origin/' not found") + strlen(branch);
- char *pattern = malloc(len);
+ char *pattern = format_string("reference 'refs/remotes/origin/%s' not found", branch);
// it seems that we sometimes get 'Reference' and sometimes 'reference'
- snprintf(pattern, len, "reference 'refs/remotes/origin/%s' not found", branch);
if (strstr(remote, prefs.cloud_git_url) && includes_string_caseinsensitive(msg, pattern)) {
/* we're trying to open the remote branch that corresponds
* to our cloud storage and the branch doesn't exist.