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 9, 2010, 21:06 UTC
Message-ID
<20100509210654.GA1637@progeny.tock>
In-Reply-To
<p2q41f08ee11005090700xdb6070dajab0e2d77b1d0f9fc@mail.gmail.com>
Hi,
Bo Yang wrote:
> git log <revision> -L1,8 -L45,+6 <file1> -L/some/,/end/ -L9,29 <file2> <file3>

I like it. It looks like paranoid script authors would have to check for paths like ‘--’ and ‘-L’ and quote them as ‘./--’ and ‘./-L’, a small price to pay for a nice syntax.

Unfortunately, this is completely incompatible with the existing blame option syntax. i.e., existing scripts might do things like this:

  git blame -L1,8 -C <file>
or
  git blame -L1,8 <rev> <file>

Maybe there should be a line range required before every file specifier in this syntax, to avoid trouble. Borrowing syntax from sed, this makes

 git log <rev> -L1,8 -L45,+6 <file1> -L/some/,/end/ -L9,29 <file2> -L1,$ <file3>
which is also a little clearer to look at, I think.
> 'git log -L1,8 <revision> -- -L1,8' .

This provides a single line range specifier for all files? Sounds convenient.

  # who wrote the opening comments?
  git blame -L '/^[/][*]/,/^ [*][/]/' -- '*.c'

Summing up, with my refinement above, a human would parse args like this:

  When an -L option is encountered, remember the current state.
  Try to parse the remaining arguments as ((-L range)* filespec)*,
  where filespec has some appropriately strict meaning that forbids
  ‘-L’ and ‘--’.  If that succeeds, we’re done.
  Otherwise, rewind.  Look for an upcoming ‘--’.  If -- is found, any
  -L arguments before the -- apply to all files specified.  Unclaimed
  arguments before the -- are revision specifiers.
  If no -- is found either, any -L arguments before the first
  unclaimed argument that is not unambiguously a revision apply to all
  files specified.  Arguments from that point on must be unambiguously
  paths.

A little hairy. Maybe you can do better, but already it seems okay. Maybe the last case ought to disallow multiple -L arguments and multiple files, to encourage people to use the first syntax or an explicit ‘--’.

Hope that helps, Jonathan

Previous: Thomas RastNext: Jonathan Nieder
Message 5 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.