git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] line-log: extract pathspec parsing from line ranges into a helper function

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Aug 21, 2019, 11:04 UTC
Message-ID
<20190821110424.18184-2-szeder.dev@gmail.com>
In-Reply-To
<20190821110424.18184-1-szeder.dev@gmail.com>

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>
---
 line-log.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/line-log.c b/line-log.c
index 3aff1849e7..fddd91f060 100644
--- a/line-log.c
+++ b/line-log.c
@@ -737,6 +737,22 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs,
 	return ret;
 }
 
+static void parse_pathspec_from_ranges(struct pathspec *pathspec,
+				       struct line_log_data *range)
+{
+	struct line_log_data *r;
+	struct argv_array array = ARGV_ARRAY_INIT;
+	const char **paths;
+
+	for (r = range; r; r = r->next)
+		argv_array_push(&array, r->path);
+	paths = argv_array_detach(&array);
+
+	parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths);
+	/* strings are now owned by pathspec */
+	free(paths);
+}
+
 void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args)
 {
 	struct commit *commit = NULL;
@@ -746,20 +762,8 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
 	range = parse_lines(rev->diffopt.repo, commit, prefix, args);
 	add_line_range(rev, commit, range);
 
-	if (!rev->diffopt.detect_rename) {
-		struct line_log_data *r;
-		struct argv_array array = ARGV_ARRAY_INIT;
-		const char **paths;
-
-		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);
-	}
+	if (!rev->diffopt.detect_rename)
+		parse_pathspec_from_ranges(&rev->diffopt.pathspec, range);
 }
 
 static void move_diff_queue(struct diff_queue_struct *dst,
-- 
2.23.0.352.gebb2b55eae
Previous: SZEDER GáborNext: SZEDER Gábor
Message 2 of 13 in “line-log: avoid unnecessary full tree diffs”
  1. 0/2 line-log: avoid unnecessary full tree diffsSZEDER Gábor, Aug 21, 2019
  2. 1/2 line-log: extract pathspec parsing from line ranges into a helper functionSZEDER Gábor, Aug 21, 2019
  3. 2/2 line-log: avoid unnecessary full tree diffsSZEDER Gábor, Aug 21, 2019
  4. Derrick StoleeAug 21, 2019
  5. SZEDER GáborAug 21, 2019
  6. Derrick StoleeAug 21, 2019
  7. SZEDER GáborAug 22, 2019
  8. Derrick StoleeAug 22, 2019
  9. Junio C HamanoAug 22, 2019
  10. SZEDER GáborAug 22, 2019
  11. Derrick StoleeAug 22, 2019
  12. SZEDER GáborAug 23, 2019
  13. Junio C HamanoAug 21, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.