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

[PATCH 3/4] line-log: optimize ranges by joining them when possible

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 4, 2018, 22:18 UTC
Message-ID
<d5d9db3c1124d29e26864596a8c36f0dc4de8a7e.1533421100.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.15.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

Technically, it is okay to have line ranges that touch (i.e. the end of the first range ends just before the next range begins). However, it is inefficient, and when the user provides such touching ranges via multiple `-L` options, we already join them.

When we traverse the history, though, we never join ranges, even they become "touchy-feely" due to added lines (which are "removed" from line-log's point of view because it traverses the commit history into the past).

Let's optimize also this case.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 line-log.c          | 4 ++++
 t/t4211-line-log.sh | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/line-log.c b/line-log.c
index d8d09b5ee..bc7ef69d6 100644
--- a/line-log.c
+++ b/line-log.c
@@ -68,6 +68,10 @@ void range_set_append_unsafe(struct range_set *rs, long a, long b)
 
 void range_set_append(struct range_set *rs, long a, long b)
 {
+	if (rs->nr > 0 && rs->ranges[rs->nr-1].end + 1 == a) {
+		rs->ranges[rs->nr-1].end = b;
+		return;
+	}
 	assert(rs->nr == 0 || rs->ranges[rs->nr-1].end <= a);
 	range_set_append_unsafe(rs, a, b);
 }
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 61ff37430..ebaf5ea86 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -119,7 +119,7 @@ q_to_lf () {
 	tr Q '\012'
 }
 
-test_expect_failure 'close to overlapping ranges' '
+test_expect_success 'close to overlapping ranges' '
 	test_seq 5 >a1.c &&
 	git add a1.c &&
 	git commit -m "5 lines" a1.c &&
-- 
gitgitgadget
Previous: Johannes SchindelinNext: Junio C Hamano
Message 11 of 20 in “line-log: be more careful when adjusting multiple line ranges”
  1. 0/4 line-log: be more careful when adjusting multiple line rangesJohannes Schindelin via GitGitGadget, Aug 4, 2018
  2. 1/4 line-log: demonstrate a bug with nearly-overlapping rangesJohannes Schindelin via GitGitGadget, Aug 4, 2018
  3. Jonathan NiederAug 5, 2018
  4. Johannes SchindelinAug 6, 2018
  5. Jonathan NiederAug 6, 2018
  6. Jonathan NiederAug 6, 2018
  7. 2/4 line-log: adjust start/end of ranges individuallyJohannes Schindelin via GitGitGadget, Aug 4, 2018
  8. Eric SunshineAug 5, 2018
  9. Eric SunshineAug 5, 2018
  10. Johannes SchindelinAug 6, 2018
  11. 3/4 line-log: optimize ranges by joining them when possibleJohannes Schindelin via GitGitGadget, Aug 4, 2018
  12. Junio C HamanoAug 5, 2018
  13. Andrei RybakAug 5, 2018
  14. Eric SunshineAug 5, 2018
  15. 4/4 line-log: convert an assertion to a full BUG() callJohannes Schindelin via GitGitGadget, Aug 4, 2018
  16. Eric SunshineAug 5, 2018
  17. Johannes SchindelinAug 6, 2018
  18. Eric SunshineAug 7, 2018
  19. Eric SunshineAug 7, 2018
  20. Eric SunshineAug 5, 2018

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.