summaryrefslogtreecommitdiff
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 17:07:43 -0400
committerJunio C Hamano <gitster@pobox.com>2015-10-05 11:08:04 -0700
commitb4600fbe071898068ef30be2766ee75880ec308b (patch)
treeee50a70d3f17743800de7bd4726cb917029a01fb /merge-recursive.c
parentbd22d4ffbc10052fef1a6c52aec066ee64236340 (diff)
downloadgit-b4600fbe071898068ef30be2766ee75880ec308b.tar.gz
merge-recursive: convert malloc / strcpy to strbuf
This would be a fairly routine use of xstrfmt, except that we need to remember the length of the result to pass to cache_name_pos. So just use a strbuf, which makes this simple. As a bonus, this gets rid of confusing references to "pathlen+1". The "1" is for the trailing slash we added, but that is automatically accounted for in the strbuf's len parameter. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 44d85bea4b..a5e74d85fd 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -630,25 +630,24 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
static int dir_in_way(const char *path, int check_working_copy)
{
- int pos, pathlen = strlen(path);
- char *dirpath = xmalloc(pathlen + 2);
+ int pos;
+ struct strbuf dirpath = STRBUF_INIT;
struct stat st;
- strcpy(dirpath, path);
- dirpath[pathlen] = '/';
- dirpath[pathlen+1] = '\0';
+ strbuf_addstr(&dirpath, path);
+ strbuf_addch(&dirpath, '/');
- pos = cache_name_pos(dirpath, pathlen+1);
+ pos = cache_name_pos(dirpath.buf, dirpath.len);
if (pos < 0)
pos = -1 - pos;
if (pos < active_nr &&
- !strncmp(dirpath, active_cache[pos]->name, pathlen+1)) {
- free(dirpath);
+ !strncmp(dirpath.buf, active_cache[pos]->name, dirpath.len)) {
+ strbuf_release(&dirpath);
return 1;
}
- free(dirpath);
+ strbuf_release(&dirpath);
return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
}