Skip to content

Commit eef5204

Browse files
szedergitster
authored andcommitted
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>
1 parent 75b2f01 commit eef5204

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

line-log.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,22 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs,
736736
return ret;
737737
}
738738

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+
739755
void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args)
740756
{
741757
struct commit *commit = NULL;
@@ -745,20 +761,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
745761
range = parse_lines(rev->diffopt.repo, commit, prefix, args);
746762
add_line_range(rev, commit, range);
747763

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);
762766
}
763767

764768
static void move_diff_queue(struct diff_queue_struct *dst,

0 commit comments

Comments
 (0)