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

[PATCH v2 10/16] log: teach -L/RE/ to search from end of previous -L range

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 6, 2013, 13:59 UTC
Message-ID
<1375797589-65308-11-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1375797589-65308-1-git-send-email-sunshine@sunshineco.com>

This is complicated slightly by having to remember the previous -L range for each file specified via -L<range>:file.

The existing implementation coalesces ranges for each file as each -L is parsed which makes it impossible to refer back to the previous -L range for any particular file. Re-implement to instead store each file's set of -L ranges verbatim, and then coalesce the ranges in a post-processing step.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 line-log.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/line-log.c b/line-log.c
index 38f827b..d40c79d 100644
--- a/line-log.c
+++ b/line-log.c
@@ -291,7 +291,6 @@ static void line_log_data_insert(struct line_log_data **list,
 
 	if (p) {
 		range_set_append_unsafe(&p->ranges, begin, end);
-		sort_and_merge_range_set(&p->ranges);
 		free(path);
 		return;
 	}
@@ -299,7 +298,6 @@ static void line_log_data_insert(struct line_log_data **list,
 	p = xcalloc(1, sizeof(struct line_log_data));
 	p->path = path;
 	range_set_append(&p->ranges, begin, end);
-	sort_and_merge_range_set(&p->ranges);
 	if (ip) {
 		p->next = ip->next;
 		ip->next = p;
@@ -566,12 +564,14 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
 	struct nth_line_cb cb_data;
 	struct string_list_item *item;
 	struct line_log_data *ranges = NULL;
+	struct line_log_data *p;
 
 	for_each_string_list_item(item, args) {
 		const char *name_part, *range_part;
 		char *full_name;
 		struct diff_filespec *spec;
 		long begin = 0, end = 0;
+		long anchor;
 
 		name_part = skip_range_arg(item->string);
 		if (!name_part || *name_part != ':' || !name_part[1])
@@ -590,8 +590,14 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
 		cb_data.lines = lines;
 		cb_data.line_ends = ends;
 
+		p = search_line_log_data(ranges, full_name, NULL);
+		if (p && p->ranges.nr)
+			anchor = p->ranges.ranges[p->ranges.nr - 1].end + 1;
+		else
+			anchor = 1;
+
 		if (parse_range_arg(range_part, nth_line, &cb_data,
-				    lines, 1, &begin, &end,
+				    lines, anchor, &begin, &end,
 				    full_name))
 			die("malformed -L argument '%s'", range_part);
 		if (lines < end || ((lines || begin) && lines < begin))
@@ -608,6 +614,9 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
 		ends = NULL;
 	}
 
+	for (p = ranges; p; p = p->next)
+		sort_and_merge_range_set(&p->ranges);
+
 	return ranges;
 }
 
-- 
1.8.4.rc1.409.gbd48715
Previous: Junio C HamanoNext: Eric Sunshine
Message 16 of 22 in “blame: accept multiple -L ranges”
  1. 00/16 blame: accept multiple -L rangesEric Sunshine, Aug 6, 2013
  2. 01/16 git-log.txt: place each -L option variation on its own lineEric Sunshine, Aug 6, 2013
  3. 02/16 line-range-format.txt: clarify -L:regex usage formEric Sunshine, Aug 6, 2013
  4. 03/16 range-set: publish API for re-use by git-blame -LEric Sunshine, Aug 6, 2013
  5. 04/16 blame: inline one-line function into its lone callerEric Sunshine, Aug 6, 2013
  6. 05/16 blame: accept multiple -L rangesEric Sunshine, Aug 6, 2013
  7. Junio C HamanoAug 6, 2013
  8. Eric SunshineAug 6, 2013
  9. Junio C HamanoAug 6, 2013
  10. 06/16 t8001/t8002: blame: add tests of multiple -L optionsEric Sunshine, Aug 6, 2013
  11. 07/16 blame: document multiple -L supportEric Sunshine, Aug 6, 2013
  12. 08/16 line-range: teach -L/RE/ to search relative to anchor pointEric Sunshine, Aug 6, 2013
  13. Junio C HamanoAug 6, 2013
  14. 09/16 blame: teach -L/RE/ to search from end of previous -L rangeEric Sunshine, Aug 6, 2013
  15. Junio C HamanoAug 6, 2013
  16. 10/16 log: teach -L/RE/ to search from end of previous -L rangeEric Sunshine, Aug 6, 2013
  17. 11/16 line-range-format.txt: document -L/RE/ relative searchEric Sunshine, Aug 6, 2013
  18. 12/16 line-range: teach -L^/RE/ to search from start of fileEric Sunshine, Aug 6, 2013
  19. 13/16 line-range: teach -L:RE to search from end of previous -L rangeEric Sunshine, Aug 6, 2013
  20. 14/16 line-range: teach -L^:RE to search from start of fileEric Sunshine, Aug 6, 2013
  21. 15/16 t8001/t8002: blame: add tests of -L line numbers less than 1Eric Sunshine, Aug 6, 2013
  22. 16/16 line-range: reject -L line numbers less than 1Eric Sunshine, Aug 6, 2013

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.