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

Re: Multiple line ranges and files in line level history browser

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 10, 2010, 09:31 UTC
Message-ID
<20100510093120.GA4445@progeny.tock>
In-Reply-To
<20100509210654.GA1637@progeny.tock>
Jonathan Nieder wrote:
>   If -- is found, any
>   -L arguments before the -- apply to all files specified.  Unclaimed
>   arguments before the -- are revision specifiers.
More comments.

The -L arguments describe lines in some particular revision of the files, so how would arbitrary ‘rev-list’-style revision specifiers work here? They don’t: in ‘blame’, one "positive" revision is allowed and the rest must be negative. Good.

The modified proposal was, roughly:
  git blame [options, no -L among them] revs ((-L range)... filespec)...
  git blame [options, -L permitted] revs -- [filespec...]
  git blame [options, -L permitted] revs [filespec...]

“...” means “one or more”. How to know whether the -L or revision arguments are encountered first? One approach is to abuse STOP_AT_NON_OPTION to catch the -L, revisions, and filespecs as they appear. Probably better would be to make -L an unknown option and rely on parse_revision_opt leaving a residue of any revisions it finds, so that after the first pass, the first syntax can be distinguished from the others by the first argument starting with "-L".

Feel free to do something else entirely (including another syntax) if you prefer, of course.

Here’s a patch that makes STOP_AT_NON_OPTION easier to abuse, without affecting current users. Maybe it would make it easier to play around.

Good night, Jonathan

 parse-options.c |    3 ++-
 parse-options.h |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 8546d85..4e3532b 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -372,7 +372,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 			if (parse_nodash_opt(ctx, arg, options) == 0)
 				continue;
 			if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
-				break;
+				return PARSE_OPT_NON_OPTION;
 			ctx->out[ctx->cpidx++] = ctx->argv[0];
 			continue;
 		}
@@ -454,6 +454,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
 	switch (parse_options_step(&ctx, options, usagestr)) {
 	case PARSE_OPT_HELP:
 		exit(129);
+	case PARSE_OPT_NON_OPTION:
 	case PARSE_OPT_DONE:
 		break;
 	default: /* PARSE_OPT_UNKNOWN */
diff --git a/parse-options.h b/parse-options.h
index 7581e93..4773cf9 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -160,6 +160,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
 enum {
 	PARSE_OPT_HELP = -1,
 	PARSE_OPT_DONE,
+	PARSE_OPT_NON_OPTION,
 	PARSE_OPT_UNKNOWN,
 };
 
-- 
1.7.1
Previous: Jonathan NiederNext: Bo Yang
Message 6 of 9 in “Multiple line ranges and files in line level history browser”
  1. Bo YangMay 9, 2010
  2. Junio C HamanoMay 9, 2010
  3. Bo YangMay 11, 2010
  4. Thomas RastMay 12, 2010
  5. Jonathan NiederMay 9, 2010
  6. Jonathan NiederMay 10, 2010
  7. Bo YangMay 11, 2010
  8. Bo YangMay 11, 2010
  9. Jonathan NiederMay 11, 2010

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.