Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: git/git
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b4a1eec332
Choose a base ref
...
head repository: git/git
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 67feca3b1c
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Aug 6, 2019

  1. revision: allow --end-of-options to end option parsing

    There's currently no robust way to tell Git that a particular option is
    meant to be a revision, and not an option. So if you have a branch
    "refs/heads/--foo", you cannot just say:
    
      git rev-list --foo
    
    You can say:
    
      git rev-list refs/heads/--foo
    
    But that breaks down if you don't know the refname, and in particular if
    you're a script passing along a value from elsewhere. In most programs,
    you can use "--" to end option parsing, like this:
    
      some-prog -- "$revision"
    
    But that doesn't work for the revision parser, because "--" is already
    meaningful there: it separates revisions from pathspecs. So we need some
    other marker to separate options from revisions.
    
    This patch introduces "--end-of-options", which serves that purpose:
    
      git rev-list --oneline --end-of-options "$revision"
    
    will work regardless of what's in "$revision" (well, if you say "--" it
    may fail, but it won't do something dangerous, like triggering an
    unexpected option).
    
    The name is verbose, but that's probably a good thing; this is meant to
    be used for scripted invocations where readability is more important
    than terseness.
    
    One alternative would be to introduce an explicit option to mark a
    revision, like:
    
      git rev-list --oneline --revision="$revision"
    
    That's slightly _more_ informative than this commit (because it makes
    even something silly like "--" unambiguous). But the pattern of using a
    separator like "--" is well established in git and in other commands,
    and it makes some scripting tasks simpler like:
    
      git rev-list --end-of-options "$@"
    
    There's no documentation in this patch, because it will make sense to
    describe the feature once it is available everywhere (and support will
    be added in further patches).
    
    Signed-off-by: Jeff King <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>
    peff authored and gitster committed Aug 6, 2019
    Configuration menu
    Copy the full SHA
    19e8789 View commit details
    Browse the repository at this point in the history
  2. parse-options: allow --end-of-options as a synonym for "--"

    The revision option parser recently learned about --end-of-options, but
    that's not quite enough for all callers. Some of them, like git-log,
    pick out some options using parse_options(), and then feed the remainder
    to setup_revisions(). For those cases we need to stop parse_options()
    from finding more options when it sees --end-of-options, and to retain
    that option in argv so that setup_revisions() can see it as well.
    
    Let's handle this the same as we do "--". We can even piggy-back on the
    handling of PARSE_OPT_KEEP_DASHDASH, because any caller that wants to
    retain one will want to retain the other.
    
    I've included two tests here. The "log" test covers "--source", which is
    one of the options it handles with parse_options(), and would fail
    before this patch. There's also a test that uses the parse-options
    helper directly. That confirms that the option is handled correctly even
    in cases without KEEP_DASHDASH or setup_revisions(). I.e., it is safe to
    use --end-of-options in place of "--" in other programs.
    
    Signed-off-by: Jeff King <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>
    peff authored and gitster committed Aug 6, 2019
    Configuration menu
    Copy the full SHA
    51b4594 View commit details
    Browse the repository at this point in the history
  3. gitcli: document --end-of-options

    Now that --end-of-options is available for any users of
    setup_revisions() or parse_options(), which should be effectively
    everywhere, we can guide people to use it for all their disambiguating
    needs.
    
    Signed-off-by: Jeff King <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>
    peff authored and gitster committed Aug 6, 2019
    Configuration menu
    Copy the full SHA
    67feca3 View commit details
    Browse the repository at this point in the history
Loading