line-log: extract pathspec parsing from line ranges into a helper function
A helper function to parse the paths involved in the line ranges and to turn them into a pathspec will be useful in the next patch. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Aug 21, 2019 at 13:04 UTC
eef5204190e6b99c9d3694fc416bd031cf253490
1 file changed
+18
-14
line-log.c
+18
-14
@@ -736,6 +736,22 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs,
736
return ret;
737
}
738
739
+static void parse_pathspec_from_ranges(struct pathspec *pathspec,
740
+ struct line_log_data *range)
741
+{
742
+ struct line_log_data *r;
743
+ struct argv_array array = ARGV_ARRAY_INIT;
744
+ const char **paths;
745
+
746
+ for (r = range; r; r = r->next)
747
+ argv_array_push(&array, r->path);
748
+ paths = argv_array_detach(&array);
749
+
750
+ parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths);
751
+ /* strings are now owned by pathspec */
752
+ free(paths);
753
+}
754
+
755
void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args)
756
{
757
struct commit *commit = NULL;
@@ -745,20 +761,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
761
range = parse_lines(rev->diffopt.repo, commit, prefix, args);
762
add_line_range(rev, commit, range);
763
748
- if (!rev->diffopt.detect_rename) {
749
- struct line_log_data *r;
750
- struct argv_array array = ARGV_ARRAY_INIT;
751
- const char **paths;
752
-
753
- for (r = range; r; r = r->next)
754
- argv_array_push(&array, r->path);
755
- paths = argv_array_detach(&array);
756
-
757
- parse_pathspec(&rev->diffopt.pathspec, 0,
758
- PATHSPEC_PREFER_FULL, "", paths);
759
- /* strings are now owned by pathspec */
760
- free(paths);
761
- }
764
+ if (!rev->diffopt.detect_rename)
765
+ parse_pathspec_from_ranges(&rev->diffopt.pathspec, range);
766
}
767
768
static void move_diff_queue(struct diff_queue_struct *dst,