Merge branch 'il/rev-glob'
authorJunio C Hamano <gitster@pobox.com>
Sat, 23 Jan 2010 00:08:16 +0000 (16:08 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Jan 2010 00:08:16 +0000 (16:08 -0800)
* il/rev-glob:
Documentation: improve description of --glob=pattern and friends
rev-parse --branches/--tags/--remotes=pattern
rev-parse --glob

1  2 
Documentation/git-log.txt
Documentation/git-rev-list.txt
Documentation/git-rev-parse.txt
builtin-rev-parse.c
revision.c
index ff4063b02028f1f08c771560263715a6e958572e,0acd526303ec4cce8e8c0d1cbefb31411b52acde..0e39bb61eebfce5d1bff032c65bf04bb77f8ce62
@@@ -14,9 -14,9 +14,9 @@@ DESCRIPTIO
  -----------
  Shows the commit logs.
  
 -The command takes options applicable to the 'git-rev-list'
 +The command takes options applicable to the 'git rev-list'
  command to control what is shown and how, and options applicable to
 -the 'git-diff-*' commands to control how the changes
 +the 'git diff-*' commands to control how the changes
  each commit introduces are shown.
  
  
@@@ -107,6 -107,17 +107,17 @@@ git log --follow builtin-rev-list.c:
        those commits that occurred before the file was given its
        present name.
  
+ git log --branches --not --remotes=origin::
+       Shows all commits that are in any of local branches but not in
+       any of remote tracking branches for 'origin' (what you have that
+       origin doesn't).
+ git log master --not --remotes=*/master::
+       Shows all commits that are in local master but not in any remote
+       repository master branches.
  Discussion
  ----------
  
index 78d3f48dfb591a0bb52229b7d16de438e55510e3,f85711676b2320a739014070b6b3486919925c5e..ae17c8a6fb816540082b8310b7f8b3f5f9f06fbe
@@@ -9,7 -9,7 +9,7 @@@ git-rev-list - Lists commit objects in 
  SYNOPSIS
  --------
  [verse]
 -'git-rev-list' [ \--max-count=number ]
 +'git rev-list' [ \--max-count=number ]
             [ \--skip=number ]
             [ \--max-age=timestamp ]
             [ \--min-age=timestamp ]
             [ \--full-history ]
             [ \--not ]
             [ \--all ]
-            [ \--branches ]
-            [ \--tags ]
-            [ \--remotes ]
+            [ \--branches[=pattern] ]
+            [ \--tags=[pattern] ]
+            [ \--remotes=[pattern] ]
+            [ \--glob=glob-pattern ]
             [ \--stdin ]
             [ \--quiet ]
             [ \--topo-order ]
@@@ -93,8 -94,8 +94,8 @@@ between the two operands.  The followin
  'rev-list' is a very essential git command, since it
  provides the ability to build and traverse commit ancestry graphs. For
  this reason, it has a lot of different options that enables it to be
 -used by commands as different as 'git-bisect' and
 -'git-repack'.
 +used by commands as different as 'git bisect' and
 +'git repack'.
  
  OPTIONS
  -------
index 818eb48d679a66fed046917f8211e3b490a80f31,61f4835a103f72c15792145cb6bfd06bdd1910eb..e7845d4055f81caf2fa92268a17837514f08c4d3
@@@ -15,16 -15,16 +15,16 @@@ DESCRIPTIO
  
  Many git porcelainish commands take mixture of flags
  (i.e. parameters that begin with a dash '-') and parameters
 -meant for the underlying 'git-rev-list' command they use internally
 +meant for the underlying 'git rev-list' command they use internally
  and flags and parameters for the other commands they use
 -downstream of 'git-rev-list'.  This command is used to
 +downstream of 'git rev-list'.  This command is used to
  distinguish between them.
  
  
  OPTIONS
  -------
  --parseopt::
 -      Use 'git-rev-parse' in option parsing mode (see PARSEOPT section below).
 +      Use 'git rev-parse' in option parsing mode (see PARSEOPT section below).
  
  --keep-dashdash::
        Only meaningful in `--parseopt` mode. Tells the option parser to echo
        that take options themself.
  
  --sq-quote::
 -      Use 'git-rev-parse' in shell quoting mode (see SQ-QUOTE
 +      Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE
        section below). In contrast to the `--sq` option below, this
        mode does only quoting. Nothing else is done to command input.
  
  --revs-only::
        Do not output flags and parameters not meant for
 -      'git-rev-list' command.
 +      'git rev-list' command.
  
  --no-revs::
        Do not output flags and parameters meant for
 -      'git-rev-list' command.
 +      'git rev-list' command.
  
  --flags::
        Do not output non-flag parameters.
@@@ -74,7 -74,7 +74,7 @@@
        properly quoted for consumption by shell.  Useful when
        you expect your parameter to contain whitespaces and
        newlines (e.g. when using pickaxe `-S` with
 -      'git-diff-\*'). In contrast to the `--sq-quote` option,
 +      'git diff-\*'). In contrast to the `--sq-quote` option,
        the command input is still interpreted as usual.
  
  --not::
  --all::
        Show all refs found in `$GIT_DIR/refs`.
  
- --branches::
-       Show branch refs found in `$GIT_DIR/refs/heads`.
- --tags::
-       Show tag refs found in `$GIT_DIR/refs/tags`.
- --remotes::
-       Show tag refs found in `$GIT_DIR/refs/remotes`.
+ --branches[=pattern]::
+ --tags[=pattern]::
+ --remotes[=pattern]::
+       Show all branches, tags, or remote-tracking branches,
+       respectively (i.e., refs found in `$GIT_DIR/refs/heads`,
+       `$GIT_DIR/refs/tags`, or `$GIT_DIR/refs/remotes`,
+       respectively).
+ +
+ If a `pattern` is given, only refs matching the given shell glob are
+ shown.  If the pattern does not contain a globbing character (`?`,
+ `\*`, or `[`), it is turned into a prefix match by appending `/\*`.
+ --glob=pattern::
+       Show all refs matching the shell glob pattern `pattern`. If
+       the pattern does not start with `refs/`, this is automatically
+       prepended.  If the pattern does not contain a globbing
+       character (`?`, `\*`, or `[`), it is turned into a prefix
+       match by appending `/\*`.
  
 +--show-toplevel::
 +      Show the absolute path of the top-level directory.
 +
  --show-prefix::
        When the command is invoked from a subdirectory, show the
        path of the current directory relative to the top-level
  --since=datestring::
  --after=datestring::
        Parse the date string, and output the corresponding
 -      --max-age= parameter for 'git-rev-list'.
 +      --max-age= parameter for 'git rev-list'.
  
  --until=datestring::
  --before=datestring::
        Parse the date string, and output the corresponding
 -      --min-age= parameter for 'git-rev-list'.
 +      --min-age= parameter for 'git rev-list'.
  
  <args>...::
        Flags and parameters to be parsed.
@@@ -174,7 -181,7 +184,7 @@@ blobs contained in a commit
    name the same commit object if there are no other object in
    your repository whose object name starts with dae86e.
  
 -* An output from 'git-describe'; i.e. a closest tag, optionally
 +* An output from 'git describe'; i.e. a closest tag, optionally
    followed by a dash and a number of commits, followed by a dash, a
    `g`, and an abbreviated object name.
  
  +
  HEAD names the commit your changes in the working tree is based on.
  FETCH_HEAD records the branch you fetched from a remote repository
 -with your last 'git-fetch' invocation.
 +with your last 'git fetch' invocation.
  ORIG_HEAD is created by commands that moves your HEAD in a drastic
  way, to record the position of the HEAD before their operation, so that
  you can change the tip of the branch back to the state before you ran
  them easily.
  MERGE_HEAD records the commit(s) you are merging into your branch
 -when you run 'git-merge'.
 +when you run 'git merge'.
  
  * A ref followed by the suffix '@' with a date specification
    enclosed in a brace
  * The special construct '@\{-<n>\}' means the <n>th branch checked out
    before the current one.
  
 +* The suffix '@{upstream}' to a ref (short form 'ref@{u}') refers to
 +  the branch the ref is set to build on top of.  Missing ref defaults
 +  to the current branch.
 +
  * A suffix '{caret}' to a revision parameter means the first parent of
    that commit object.  '{caret}<n>' means the <n>th parent (i.e.
    'rev{caret}'
@@@ -315,7 -318,7 +325,7 @@@ G   H   I   
  SPECIFYING RANGES
  -----------------
  
 -History traversing commands such as 'git-log' operate on a set
 +History traversing commands such as 'git log' operate on a set
  of commits, not just a single commit.  To these commands,
  specifying a single revision with the notation described in the
  previous section means the set of commits reachable from that
@@@ -356,7 -359,7 +366,7 @@@ Here are a handful of examples
  PARSEOPT
  --------
  
 -In `--parseopt` mode, 'git-rev-parse' helps massaging options to bring to shell
 +In `--parseopt` mode, 'git rev-parse' helps massaging options to bring to shell
  scripts the same facilities C builtins have. It works as an option normalizer
  (e.g. splits single switches aggregate values), a bit like `getopt(1)` does.
  
@@@ -368,7 -371,7 +378,7 @@@ usage on the standard error stream, an
  Input Format
  ~~~~~~~~~~~~
  
 -'git-rev-parse --parseopt' input format is fully text based. It has two parts,
 +'git rev-parse --parseopt' input format is fully text based. It has two parts,
  separated by a line that contains only `--`. The lines before the separator
  (should be more than one) are used for the usage.
  The lines after the separator describe the options.
@@@ -427,13 -430,13 +437,13 @@@ eval `echo "$OPTS_SPEC" | git rev-pars
  SQ-QUOTE
  --------
  
 -In `--sq-quote` mode, 'git-rev-parse' echoes on the standard output a
 +In `--sq-quote` mode, 'git rev-parse' echoes on the standard output a
  single line suitable for `sh(1)` `eval`. This line is made by
  normalizing the arguments following `--sq-quote`. Nothing other than
  quoting the arguments is done.
  
  If you want command input to still be interpreted as usual by
 -'git-rev-parse' before the output is shell quoted, see the `--sq`
 +'git rev-parse' before the output is shell quoted, see the `--sq`
  option.
  
  Example
diff --combined builtin-rev-parse.c
index cbe5b428ad23708338dc7b11cb0105f53b045527,d14fe20692aa0903f45da96bf9f31f4564b7816a..a8c5043dedd785b8fc43c0921edd01e2adac65e1
@@@ -41,6 -41,7 +41,7 @@@ static int is_rev_argument(const char *
                "--all",
                "--bisect",
                "--dense",
+               "--branches=",
                "--branches",
                "--header",
                "--max-age=",
                "--objects-edge",
                "--parents",
                "--pretty",
+               "--remotes=",
                "--remotes",
+               "--glob=",
                "--sparse",
+               "--tags=",
                "--tags",
                "--topo-order",
                "--date-order",
@@@ -569,24 -573,37 +573,43 @@@ int cmd_rev_parse(int argc, const char 
                                for_each_ref_in("refs/bisect/good", anti_reference, NULL);
                                continue;
                        }
+                       if (!prefixcmp(arg, "--branches=")) {
+                               for_each_glob_ref_in(show_reference, arg + 11,
+                                       "refs/heads/", NULL);
+                               continue;
+                       }
                        if (!strcmp(arg, "--branches")) {
                                for_each_branch_ref(show_reference, NULL);
                                continue;
                        }
+                       if (!prefixcmp(arg, "--tags=")) {
+                               for_each_glob_ref_in(show_reference, arg + 7,
+                                       "refs/tags/", NULL);
+                               continue;
+                       }
                        if (!strcmp(arg, "--tags")) {
                                for_each_tag_ref(show_reference, NULL);
                                continue;
                        }
+                       if (!prefixcmp(arg, "--glob=")) {
+                               for_each_glob_ref(show_reference, arg + 7, NULL);
+                               continue;
+                       }
+                       if (!prefixcmp(arg, "--remotes=")) {
+                               for_each_glob_ref_in(show_reference, arg + 10,
+                                       "refs/remotes/", NULL);
+                               continue;
+                       }
                        if (!strcmp(arg, "--remotes")) {
                                for_each_remote_ref(show_reference, NULL);
                                continue;
                        }
 +                      if (!strcmp(arg, "--show-toplevel")) {
 +                              const char *work_tree = get_git_work_tree();
 +                              if (work_tree)
 +                                      puts(work_tree);
 +                              continue;
 +                      }
                        if (!strcmp(arg, "--show-prefix")) {
                                if (prefix)
                                        puts(prefix);
diff --combined revision.c
index 4e1a299bfb822caa3eec94baca375de301a4cd73,1e9277d335aa4a5469f380c16b040c886b34ea5c..f54d43ffb39dcd3600e85458b93e624a2a6ab159
@@@ -268,7 -268,7 +268,7 @@@ static int tree_difference = REV_TREE_S
  static void file_add_remove(struct diff_options *options,
                    int addremove, unsigned mode,
                    const unsigned char *sha1,
 -                  const char *fullpath)
 +                  const char *fullpath, unsigned dirty_submodule)
  {
        int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD;
  
@@@ -281,8 -281,7 +281,8 @@@ static void file_change(struct diff_opt
                 unsigned old_mode, unsigned new_mode,
                 const unsigned char *old_sha1,
                 const unsigned char *new_sha1,
 -               const char *fullpath)
 +               const char *fullpath,
 +               unsigned old_dirty_submodule, unsigned new_dirty_submodule)
  {
        tree_difference = REV_TREE_DIFFERENT;
        DIFF_OPT_SET(options, HAS_CHANGES);
@@@ -700,12 -699,18 +700,18 @@@ static int handle_one_ref(const char *p
        return 0;
  }
  
+ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
+       unsigned flags)
+ {
+       cb->all_revs = revs;
+       cb->all_flags = flags;
+ }
  static void handle_refs(struct rev_info *revs, unsigned flags,
                int (*for_each)(each_ref_fn, void *))
  {
        struct all_refs_cb cb;
-       cb.all_revs = revs;
-       cb.all_flags = flags;
+       init_all_refs_cb(&cb, revs, flags);
        for_each(handle_one_ref, &cb);
  }
  
@@@ -1162,22 -1167,13 +1168,22 @@@ static int handle_revision_opt(struct r
                revs->verbose_header = 1;
        } else if (!strcmp(arg, "--pretty")) {
                revs->verbose_header = 1;
 +              revs->pretty_given = 1;
                get_commit_format(arg+8, revs);
        } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
                revs->verbose_header = 1;
 +              revs->pretty_given = 1;
                get_commit_format(arg+9, revs);
 +      } else if (!strcmp(arg, "--show-notes")) {
 +              revs->show_notes = 1;
 +              revs->show_notes_given = 1;
 +      } else if (!strcmp(arg, "--no-notes")) {
 +              revs->show_notes = 0;
 +              revs->show_notes_given = 1;
        } else if (!strcmp(arg, "--oneline")) {
                revs->verbose_header = 1;
                get_commit_format("oneline", revs);
 +              revs->pretty_given = 1;
                revs->abbrev_commit = 1;
        } else if (!strcmp(arg, "--graph")) {
                revs->topo_order = 1;
@@@ -1362,6 -1358,30 +1368,30 @@@ int setup_revisions(int argc, const cha
                                handle_refs(revs, flags, for_each_remote_ref);
                                continue;
                        }
+                       if (!prefixcmp(arg, "--glob=")) {
+                               struct all_refs_cb cb;
+                               init_all_refs_cb(&cb, revs, flags);
+                               for_each_glob_ref(handle_one_ref, arg + 7, &cb);
+                               continue;
+                       }
+                       if (!prefixcmp(arg, "--branches=")) {
+                               struct all_refs_cb cb;
+                               init_all_refs_cb(&cb, revs, flags);
+                               for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
+                               continue;
+                       }
+                       if (!prefixcmp(arg, "--tags=")) {
+                               struct all_refs_cb cb;
+                               init_all_refs_cb(&cb, revs, flags);
+                               for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
+                               continue;
+                       }
+                       if (!prefixcmp(arg, "--remotes=")) {
+                               struct all_refs_cb cb;
+                               init_all_refs_cb(&cb, revs, flags);
+                               for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
+                               continue;
+                       }
                        if (!strcmp(arg, "--reflog")) {
                                handle_reflog(revs, flags);
                                continue;