aboutsummaryrefslogtreecommitdiffstats
path: root/line-log.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:44:21 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:50:32 -0800
commit850d2fec53ee188bab9e458f77906041ac7f1904 (patch)
tree159000ee6af85ab7e33477c9e94ff42e4c942a7f /line-log.c
parentb992657ed0e2720e20302b0ac8c210dff55950b2 (diff)
downloadgit-850d2fec53ee188bab9e458f77906041ac7f1904.tar.gz
convert manual allocations to argv_array
There are many manual argv allocations that predate the argv_array API. Switching to that API brings a few advantages: 1. We no longer have to manually compute the correct final array size (so it's one less thing we can screw up). 2. In many cases we had to make a separate pass to count, then allocate, then fill in the array. Now we can do it in one pass, making the code shorter and easier to follow. 3. argv_array handles memory ownership for us, making it more obvious when things should be free()d and and when not. Most of these cases are pretty straightforward. In some, we switch from "run_command_v" to "run_command" which lets us directly use the argv_array embedded in "struct child_process". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'line-log.c')
-rw-r--r--line-log.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/line-log.c b/line-log.c
index af6e2f799e..5877986c5a 100644
--- a/line-log.c
+++ b/line-log.c
@@ -14,6 +14,7 @@
#include "graph.h"
#include "userdiff.h"
#include "line-log.h"
+#include "argv-array.h"
static void range_set_grow(struct range_set *rs, size_t extra)
{
@@ -746,22 +747,17 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
add_line_range(rev, commit, range);
if (!rev->diffopt.detect_rename) {
- int i, count = 0;
- struct line_log_data *r = range;
+ struct line_log_data *r;
+ struct argv_array array = ARGV_ARRAY_INIT;
const char **paths;
- while (r) {
- count++;
- r = r->next;
- }
- paths = xmalloc((count+1)*sizeof(char *));
- r = range;
- for (i = 0; i < count; i++) {
- paths[i] = xstrdup(r->path);
- r = r->next;
- }
- paths[count] = NULL;
+
+ for (r = range; r; r = r->next)
+ argv_array_push(&array, r->path);
+ paths = argv_array_detach(&array);
+
parse_pathspec(&rev->diffopt.pathspec, 0,
PATHSPEC_PREFER_FULL, "", paths);
+ /* strings are now owned by pathspec */
free(paths);
}
}