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

[PATCH 1/6] line-range: fix "blame -L X,-N" regression

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 17, 2013, 21:25 UTC
Message-ID
<1374096332-7891-2-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1374096332-7891-1-git-send-email-sunshine@sunshineco.com>

"blame -L X,-N" is documented as blaming "N lines ending at X". In practice, the behavior is achieved by swapping the two range endpoints if the second is less than the first. 25ed3412 (Refactor parse_loc; 2013-03-28) broke this interpretation by removing the swapping code from blame.c and failing to add it to line-range.c along with other code relocated from blame.c. Thus, such a range is effectively treated as empty. Fix this regression.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 line-range.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/line-range.c b/line-range.c
index 8faf943..3942475 100644
--- a/line-range.c
+++ b/line-range.c
@@ -211,6 +211,8 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
 		    void *cb_data, long lines, long *begin, long *end,
 		    const char *path)
 {
+	*begin = *end = 0;
+
 	if (*arg == ':') {
 		arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, begin, end, path);
 		if (!arg || *arg)
@@ -226,6 +228,11 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb,
 	if (*arg)
 		return -1;
 
+	if (*begin && *end && *end < *begin) {
+		long tmp;
+		tmp = *end; *end = *begin; *begin = tmp;
+	}
+
 	return 0;
 }
 
-- 
1.8.3.3.1016.g4f0baba
Previous: Eric SunshineNext: Eric Sunshine
Message 2 of 12 in “fix blame -L regression; add tests”
  1. 0/6 fix blame -L regression; add testsEric Sunshine, Jul 17, 2013
  2. 1/6 line-range: fix "blame -L X,-N" regressionEric Sunshine, Jul 17, 2013
  3. 2/6 t8001/t8002 (blame): modernize styleEric Sunshine, Jul 17, 2013
  4. 3/6 t8001/t8002 (blame): add blame -L testsEric Sunshine, Jul 17, 2013
  5. 4/6 t8001/t8002 (blame): add blame -L :funcname testsEric Sunshine, Jul 17, 2013
  6. 5/6 blame-options.txt: place each -L option variation on its own lineEric Sunshine, Jul 17, 2013
  7. Thomas RastJul 18, 2013
  8. Junio C HamanoJul 18, 2013
  9. Thomas RastJul 22, 2013
  10. Junio C HamanoJul 22, 2013
  11. 6/6 blame-options.txt: explain that -L <start> and <end> are optionalEric Sunshine, Jul 17, 2013
  12. Thomas RastJul 18, 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.