1. 04 8月, 2017 1 次提交
  2. 03 8月, 2017 1 次提交
  3. 18 7月, 2017 3 次提交
    • B
      sha1_name: convert GET_SHA1* flags to GET_OID* · 321c89bf
      brian m. carlson 提交于
      Convert the flags for get_oid_with_context and friends to use "OID"
      instead of "SHA1" in their names.
      
      This transform was made by running the following one-liner on the
      affected files:
      
        perl -pi -e 's/GET_SHA1/GET_OID/g'
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      321c89bf
    • B
      sha1_name: convert get_sha1* to get_oid* · e82caf38
      brian m. carlson 提交于
      Now that all the callers of get_sha1 directly or indirectly use struct
      object_id, rename the functions starting with get_sha1 to start with
      get_oid.  Convert the internals in sha1_name.c to use struct object_id
      as well, and eliminate explicit length checks where possible.  Convert a
      use of 40 in get_oid_basic to GIT_SHA1_HEXSZ.
      
      Outside of sha1_name.c and cache.h, this transition was made with the
      following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - get_sha1(E1, E2.hash)
      + get_oid(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1(E1, E2->hash)
      + get_oid(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_committish(E1, E2.hash)
      + get_oid_committish(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_committish(E1, E2->hash)
      + get_oid_committish(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_treeish(E1, E2.hash)
      + get_oid_treeish(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_treeish(E1, E2->hash)
      + get_oid_treeish(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_commit(E1, E2.hash)
      + get_oid_commit(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_commit(E1, E2->hash)
      + get_oid_commit(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_tree(E1, E2.hash)
      + get_oid_tree(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_tree(E1, E2->hash)
      + get_oid_tree(E1, E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_blob(E1, E2.hash)
      + get_oid_blob(E1, &E2)
      
      @@
      expression E1, E2;
      @@
      - get_sha1_blob(E1, E2->hash)
      + get_oid_blob(E1, E2)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - get_sha1_with_context(E1, E2, E3.hash, E4)
      + get_oid_with_context(E1, E2, &E3, E4)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - get_sha1_with_context(E1, E2, E3->hash, E4)
      + get_oid_with_context(E1, E2, E3, E4)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e82caf38
    • B
  4. 14 7月, 2017 1 次提交
    • J
      color: check color.ui in git_default_config() · 136c8c8b
      Jeff King 提交于
      Back in prehistoric times, our decision on whether or not to
      show color by default relied on using a config callback that
      either did or didn't load color config like color.diff.
      When we introduced color.ui, we put it in the same boat:
      commands had to manually respect it by using git_color_config()
      or its git_color_default_config() convenience wrapper.
      
      But in 4c7f1819 (make color.ui default to 'auto',
      2013-06-10), that changed. Since then, we default color.ui
      to auto in all programs, meaning that even plumbing commands
      like "git diff-tree --pretty" might colorize the output.
      Nobody seems to have complained in the intervening years,
      presumably because the "is stdout a tty" check does a good
      job of catching the right cases.
      
      But that leaves an interesting curiosity: color.ui defaults
      to auto even in plumbing, but you can't actually _disable_
      the color via config. So if you really hate color and set
      "color.ui" to false, diff-tree will still show color (but
      porcelain like git-diff won't).  Nobody noticed that either,
      probably because very few people disable color.
      
      One could argue that the plumbing should _always_ disable
      color unless an explicit --color option is given on the
      command line. But in practice, this creates a lot of
      complications for scripts which do want plumbing to show
      user-visible output. They can't just pass "--color" blindly;
      they need to check the user's config and decide what to
      send.
      
      Given that nobody has complained about the current behavior,
      let's assume it's a good path, and follow it to its
      conclusion: supporting color.ui everywhere.
      
      Note that you can create havoc by setting color.ui=always in
      your config, but that's more or less already the case. We
      could disallow it entirely, but it is handy for one-offs
      like:
      
        git -c color.ui=always foo >not-a-tty
      
      when "foo" does not take a --color option itself.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      136c8c8b
  5. 11 7月, 2017 1 次提交
  6. 01 7月, 2017 1 次提交
    • Æ
      grep: remove regflags from the public grep_opt API · 07a3d411
      Ævar Arnfjörð Bjarmason 提交于
      Refactor calls to the grep machinery to always pass opt.ignore_case &
      opt.extended_regexp_option instead of setting the equivalent regflags
      bits.
      
      The bug fixed when making -i work with -P in commit 9e3cbc59 ("log:
      make --regexp-ignore-case work with --perl-regexp", 2017-05-20) was
      really just plastering over the code smell which this change fixes.
      
      The reason for adding the extensive commentary here is that I
      discovered some subtle complexity in implementing this that really
      should be called out explicitly to future readers.
      
      Before this change we'd rely on the difference between
      `extended_regexp_option` and `regflags` to serve as a membrane between
      our preliminary parsing of grep.extendedRegexp and grep.patternType,
      and what we decided to do internally.
      
      Now that those two are the same thing, it's necessary to unset
      `extended_regexp_option` just before we commit in cases where both of
      those config variables are set. See 84befcd0 ("grep: add a
      grep.patternType configuration setting", 2012-08-03) for the code and
      documentation related to that.
      
      The explanation of why the if/else branches in
      grep_commit_pattern_type() are ordered the way they are exists in that
      commit message, but I think it's worth calling this subtlety out
      explicitly with a comment for future readers.
      
      Even though grep_commit_pattern_type() is the only caller of
      grep_set_pattern_type_option() it's simpler to reset the
      extended_regexp_option flag in the latter, since 2/3 branches in the
      former would otherwise need to reset it, this way we can do it in one
      place.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      07a3d411
  7. 28 6月, 2017 1 次提交
  8. 24 6月, 2017 1 次提交
  9. 16 6月, 2017 1 次提交
  10. 02 6月, 2017 1 次提交
  11. 01 6月, 2017 1 次提交
    • S
      builtin/grep.c: respect 'submodule.recurse' option · 9071c078
      Stefan Beller 提交于
      In builtin/grep.c we parse the config before evaluating the command line
      options. This makes the task of teaching grep to respect the new config
      option 'submodule.recurse' very easy by just parsing that option.
      
      As an alternative I had implemented a similar structure to treat
      submodules as the fetch/push command have, including
      * aligning the meaning of the 'recurse_submodules' to possible submodule
        values RECURSE_SUBMODULES_* as defined in submodule.h.
      * having a callback to parse the value and
      * reacting to the RECURSE_SUBMODULES_DEFAULT state that was the initial
        state.
      
      However all this is not needed for a true boolean value, so let's keep
      it simple. However this adds another place where "submodule.recurse" is
      parsed.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9071c078
  12. 26 5月, 2017 5 次提交
    • Æ
      grep: skip pthreads overhead when using one thread · 9ec726a4
      Ævar Arnfjörð Bjarmason 提交于
      Skip the administrative overhead of using pthreads when only using one
      thread. Instead take the non-threaded path which would be taken under
      NO_PTHREADS.
      
      The threading support was initially added in commit
      5b594f45 ("Threaded grep", 2010-01-25) with a hardcoded compile-time
      number of 8 threads. Later the number of threads was made configurable
      in commit 89f09dd3 ("grep: add --threads=<num> option and
      grep.threads configuration", 2015-12-15).
      
      That change did not add any special handling for --threads=1. Now we
      take a slightly faster path by skipping thread handling entirely when
      1 thread is requested.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9ec726a4
    • Æ
      grep: don't redundantly compile throwaway patterns under threading · 6d423dd5
      Ævar Arnfjörð Bjarmason 提交于
      Change the pattern compilation logic under threading so that grep
      doesn't compile a pattern it never ends up using on the non-threaded
      code path, only to compile it again N times for N threads which will
      each use their own copy, ignoring the initially compiled pattern.
      
      This redundant compilation dates back to the initial introduction of
      the threaded grep in commit 5b594f45 ("Threaded grep",
      2010-01-25).
      
      There was never any reason for doing this redundant work other than an
      oversight in the initial commit. Jeff King suggested on-list in
      <20170414212325.fefrl3qdjigwyitd@sigill.intra.peff.net> that this
      might be needed to check the pattern for sanity before threaded
      execution commences.
      
      That's not the case. The pattern is compiled under threading in
      start_threads() before any concurrent execution has started by calling
      pthread_create(), so if the pattern contains an error we still do the
      right thing. I.e. die with one error before any threaded execution has
      commenced, instead of e.g. spewing out an error for each N threads,
      which could be a regression a change like this might inadvertently
      introduce.
      
      This change is not meant as an optimization, any performance gains
      from this are in the hundreds to thousands of nanoseconds at most. If
      we wanted more performance here we could just re-use the compiled
      patterns in multiple threads (regcomp(3) is thread-safe), or partially
      re-use them and the associated structures in the case of later PCRE
      JIT changes.
      
      Rather, it's just to make the code easier to reason about. It's
      confusing to debug this under threading & non-threading when the
      threading codepaths redundantly compile a pattern which is never used.
      
      The reason the patterns are recompiled is as a side-effect of
      duplicating the whole grep_opt structure, which is not thread safe,
      writable, and munged during execution. The grep_opt structure then
      points to the grep_pat structure where pattern or patterns are stored.
      
      I looked into e.g. splitting the API into some "do & alloc threadsafe
      stuff", "spawn thread", "do and alloc non-threadsafe stuff", but the
      execution time of grep_opt_dup() & pattern compilation is trivial
      compared to actually executing the grep, so there was no point. Even
      with the more expensive JIT changes to follow the most expensive PCRE
      patterns take something like 0.0X milliseconds to compile at most[1].
      
      The undocumented --debug mode added in commit 17bf35a3 ("grep: teach
      --debug option to dump the parse tree", 2012-09-13) still works
      properly with this change. It only emits debugging info during pattern
      compilation, which is now dumped by the pattern compiled just before
      the first thread is started.
      
      1. http://sljit.sourceforge.net/pcre.htmlSigned-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6d423dd5
    • Æ
      grep: assert that threading is enabled when calling grep_{lock,unlock} · 8df4c295
      Ævar Arnfjörð Bjarmason 提交于
      Change the grep_{lock,unlock} functions to assert that num_threads is
      true, instead of only locking & unlocking the pthread mutex lock when
      it is.
      
      These functions are never called when num_threads isn't true, this
      logic has gone through multiple iterations since the initial
      introduction of grep threading in commit 5b594f45 ("Threaded grep",
      2010-01-25), but ever since then they'd only be called if num_threads
      was true, so this check made the code confusing to read.
      
      Replace the check with an assertion, so that it's clear to the reader
      that this code path is never taken unless we're spawning threads.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8df4c295
    • Æ
      grep: given --threads with NO_PTHREADS=YesPlease, warn · d1edee4a
      Ævar Arnfjörð Bjarmason 提交于
      Add a warning about missing thread support when grep.threads or
      --threads is set to a non 0 (default) or 1 (no parallelism) value
      under NO_PTHREADS=YesPlease.
      
      This is for consistency with the index-pack & pack-objects commands,
      which also take a --threads option & are configurable via
      pack.threads, and have long warned about the same under
      NO_PTHREADS=YesPlease.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d1edee4a
    • Æ
      grep: catch a missing enum in switch statement · 374166cb
      Ævar Arnfjörð Bjarmason 提交于
      Add a die(...) to a default case for the switch statement selecting
      between grep pattern types under --recurse-submodules.
      
      Normally this would be caught by -Wswitch, but the grep_pattern_type
      type is converted to int by going through parse_options(). Changing
      the argument type passed to compile_submodule_options() won't work,
      the value will just get coerced. The -Wswitch-default warning will
      warn about it, but that produces a lot of noise across the codebase,
      this potential issue would be drowned in that noise.
      
      Thus catching this at runtime is the least bad option. This won't ever
      trigger in practice, but if a new pattern type were to be added this
      catches an otherwise silent bug during development.
      
      See commit 0281e487 ("grep: optionally recurse into submodules",
      2016-12-16) for the initial addition of this code.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      374166cb
  13. 24 5月, 2017 1 次提交
    • J
      get_sha1_with_context: dynamically allocate oc->path · dc944b65
      Jeff King 提交于
      When a sha1 lookup returns the tree path via "struct
      object_context", it just copies it into a fixed-size buffer.
      This means the result can be truncated, and it means our
      "struct object_context" consumes a lot of stack space.
      
      Instead, let's allocate a string on the heap. Because most
      callers don't care about this information, we'll avoid doing
      it by default (so they don't all have to start calling
      free() on the result). There are basically two options for
      the caller to signal to us that it's interested:
      
        1. By setting a pointer to storage in the object_context.
      
        2. By passing a flag in another parameter.
      
      Doing (1) would match the way that sha1_object_info_extended()
      works. But it would mean that every caller would have to
      initialize the object_context, which they don't currently
      have to do.
      
      This patch does (2), and adds a new bit to the function's
      flags field. All of the callers that look at the "path"
      field are updated to pass the new flag.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dc944b65
  14. 08 5月, 2017 1 次提交
    • B
      object: convert parse_object* to take struct object_id · c251c83d
      brian m. carlson 提交于
      Make parse_object, parse_object_or_die, and parse_object_buffer take a
      pointer to struct object_id.  Remove the temporary variables inserted
      earlier, since they are no longer necessary.  Transform all of the
      callers using the following semantic patch:
      
      @@
      expression E1;
      @@
      - parse_object(E1.hash)
      + parse_object(&E1)
      
      @@
      expression E1;
      @@
      - parse_object(E1->hash)
      + parse_object(E1)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1.hash, E2)
      + parse_object_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1->hash, E2)
      + parse_object_or_die(E1, E2)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1.hash, E2, E3, E4, E5)
      + parse_object_buffer(&E1, E2, E3, E4, E5)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1->hash, E2, E3, E4, E5)
      + parse_object_buffer(E1, E2, E3, E4, E5)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c251c83d
  15. 06 5月, 2017 1 次提交
  16. 17 4月, 2017 1 次提交
    • Æ
      grep: plug a trivial memory leak · 7861fa07
      Ævar Arnfjörð Bjarmason 提交于
      Change the cleanup phase for the grep command to free the pathspec
      struct that's allocated earlier in the same block, and used just a few
      lines earlier.
      
      With "grep hi README.md" valgrind reports a loss of 239 bytes now,
      down from 351.
      
      The relevant --num-callers=40 --leak-check=full --show-leak-kinds=all
      backtrace is:
      
          [...] 187 (112 direct, 75 indirect) bytes in 1 blocks are definitely lost in loss record 70 of 110
          [...]    at 0x4C2BBAF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
          [...]    by 0x60B339: do_xmalloc (wrapper.c:59)
          [...]    by 0x60B2F6: xmalloc (wrapper.c:86)
          [...]    by 0x576B37: parse_pathspec (pathspec.c:652)
          [...]    by 0x4519F0: cmd_grep (grep.c:1215)
          [...]    by 0x4062EF: run_builtin (git.c:371)
          [...]    by 0x40544D: handle_builtin (git.c:572)
          [...]    by 0x4060A2: run_argv (git.c:624)
          [...]    by 0x4051C6: cmd_main (git.c:701)
          [...]    by 0x4C5901: main (common-main.c:43)
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Acked-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7861fa07
  17. 19 3月, 2017 1 次提交
  18. 18 3月, 2017 2 次提交
    • B
      grep: fix bug when recursing with relative pathspec · be80a239
      Brandon Williams 提交于
      When using the --recurse-submodules flag with a relative pathspec which
      includes "..", an error is produced inside the child process spawned for
      a submodule.  When creating the pathspec struct in the child, the ".."
      is interpreted to mean "go up a directory" which causes an error stating
      that the path ".." is outside of the repository.
      
      While it is true that ".." is outside the scope of the submodule, it is
      confusing to a user who originally invoked the command where ".." was
      indeed still inside the scope of the superproject.  Since the child
      process launched for the submodule has some context that it is operating
      underneath a superproject, this error could be avoided.
      
      This patch fixes the bug by passing the 'prefix' to the child process.
      Now each child process that works on a submodule has two points of
      reference to the superproject: (1) the 'super_prefix' which is the path
      from the root of the superproject down to root of the submodule and (2)
      the 'prefix' which is the path from the root of the superproject down to
      the directory where the user invoked the git command.
      
      With these two pieces of information a child process can correctly
      interpret the pathspecs provided by the user as well as being able to
      properly format its output relative to the directory the user invoked
      the original command from.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be80a239
    • B
      grep: fix help text typo · 4fb1c6aa
      Brandon Williams 提交于
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4fb1c6aa
  19. 16 3月, 2017 1 次提交
  20. 23 2月, 2017 1 次提交
  21. 15 2月, 2017 7 次提交
    • J
      grep: treat revs the same for --untracked as for --no-index · 131f3c96
      Jeff King 提交于
      git-grep has always disallowed grepping in a tree (as
      opposed to the working directory) with both --untracked
      and --no-index. But we traditionally did so by first
      collecting the revs, and then complaining when any were
      provided.
      
      The --no-index option recently learned to detect revs
      much earlier. This has two user-visible effects:
      
        - we don't bother to resolve revision names at all. So
          when there's a rev/path ambiguity, we always choose to
          treat it as a path.
      
        - likewise, when you do specify a revision without "--",
          the error you get is "no such path" and not "--untracked
          cannot be used with revs".
      
      The rationale for doing this with --no-index is that it is
      meant to be used outside a repository, and so parsing revs
      at all does not make sense.
      
      This patch gives --untracked the same treatment. While it
      _is_ meant to be used in a repository, it is explicitly
      about grepping the non-repository contents. Telling the user
      "we found a rev, but you are not allowed to use revs" is
      not really helpful compared to "we treated your argument as
      a path, and could not find it".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      131f3c96
    • J
      grep: do not diagnose misspelt revs with --no-index · 73fc7b6b
      Jeff King 提交于
      If we are using --no-index, then our arguments cannot be
      revs in the first place. Not only is it pointless to
      diagnose them, but if we are not in a repository, we should
      not be trying to resolve any names.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      73fc7b6b
    • J
      grep: avoid resolving revision names in --no-index case · d0ffc069
      Jeff King 提交于
      We disallow the use of revisions with --no-index, but we
      don't actually check and complain until well after we've
      parsed the revisions.
      
      This is the cause of a few problems:
      
       1. We shouldn't be calling get_sha1() at all when we aren't
          in a repository, as it might access the ref or object
          databases. For now, this should generally just return
          failure, but eventually it will become a BUG().
      
       2. When there's a "--" disambiguator and you're outside a
          repository, we'll complain early with "unable to resolve
          revision". But we can give a much more specific error.
      
       3. When there isn't a "--" disambiguator, we still do the
          normal rev/path checks. This is silly, as we know we
          cannot have any revs with --no-index. Everything we see
          must be a path.
      
          Outside of a repository this doesn't matter (since we
          know it won't resolve), but inside one, we may complain
          unnecessarily if a filename happens to also match a
          refname.
      
      This patch skips the get_sha1() call entirely in the
      no-index case, and behaves as if it failed (with the
      exception of giving a better error message).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d0ffc069
    • J
      grep: fix "--" rev/pathspec disambiguation · b5b81136
      Jeff King 提交于
      If we see "git grep pattern rev -- file" then we apply the
      usual rev/pathspec disambiguation rules: any "rev" before
      the "--" must be a revision, and we do not need to apply the
      verify_non_filename() check.
      
      But there are two bugs here:
      
        1. We keep a seen_dashdash flag to handle this case, but
           we set it in the same left-to-right pass over the
           arguments in which we parse "rev".
      
           So when we see "rev", we do not yet know that there is
           a "--", and we mistakenly complain if there is a
           matching file.
      
           We can fix this by making a preliminary pass over the
           arguments to find the "--", and only then checking the rev
           arguments.
      
        2. If we can't resolve "rev" but there isn't a dashdash,
           that's OK. We treat it like a path, and complain later
           if it doesn't exist.
      
           But if there _is_ a dashdash, then we know it must be a
           rev, and should treat it as such, complaining if it
           does not resolve. The current code instead ignores it
           and tries to treat it like a path.
      
      This patch fixes both bugs, and tries to comment the parsing
      flow a bit better.
      
      It adds tests that cover the two bugs, but also some related
      situations (which already worked, but this confirms that our
      fixes did not break anything).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b5b81136
    • J
      grep: re-order rev-parsing loop · 20d6421c
      Jeff King 提交于
      We loop over the arguments, but every branch of the loop
      hits either a "continue" or a "break". Surely we can make
      this simpler.
      
      The final conditional is:
      
        if (arg is a rev) {
      	  ... handle rev ...
      	  continue;
        }
        break;
      
      We can rewrite this as:
      
        if (arg is not a rev)
      	  break;
      
        ... handle rev ...
      
      That makes the flow a little bit simpler, and will make
      things much easier to follow when we add more logic in
      future patches.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      20d6421c
    • J
      grep: do not unnecessarily query repo for "--" · dca3b5f5
      Jonathan Tan 提交于
      When running a command of the form
      
        git grep --no-index pattern -- path
      
      in the absence of a Git repository, an error message will be printed:
      
        fatal: BUG: setup_git_env called without repository
      
      This is because "git grep" tries to interpret "--" as a rev. "git grep"
      has always tried to first interpret "--" as a rev for at least a few
      years, but this issue was upgraded from a pessimization to a bug in
      commit 59332d13 ("Resurrect "git grep --no-index"", 2010-02-06), which
      calls get_sha1 regardless of whether --no-index was specified. This bug
      appeared to be benign until commit b1ef400e ("setup_git_env: avoid blind
      fall-back to ".git"", 2016-10-20) when Git was taught to die in this
      situation.  (This "git grep" bug appears to be one of the bugs that
      commit b1ef400e is meant to flush out.)
      
      Therefore, always interpret "--" as signaling the end of options,
      instead of trying to interpret it as a rev first.
      Signed-off-by: NJonathan Tan <jonathantanmy@google.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dca3b5f5
    • J
      grep: move thread initialization a little lower · a0fe2b0d
      Jeff King 提交于
      Originally, we set up the threads for grep before parsing
      the non-option arguments. In 53b8d931 (grep: disable
      threading in non-worktree case, 2011-12-12), the thread code
      got bumped lower in the function because it now needed to
      know whether we got any revision arguments.
      
      That put a big block of code in between the parsing of revs
      and the parsing of pathspecs, both of which share some loop
      variables. That makes it harder to read the code than the
      original, where the shared loops were right next to each
      other.
      
      Let's bump the thread initialization until after all of the
      parsing is done.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a0fe2b0d
  22. 23 12月, 2016 3 次提交
    • B
      grep: search history of moved submodules · e6fac7f3
      Brandon Williams 提交于
      If a submodule was renamed at any point since it's inception then if you
      were to try and grep on a commit prior to the submodule being moved, you
      wouldn't be able to find a working directory for the submodule since the
      path in the past is different from the current path.
      
      This patch teaches grep to find the .git directory for a submodule in
      the parents .git/modules/ directory in the event the path to the
      submodule in the commit that is being searched differs from the state of
      the currently checked out commit.  If found, the child process that is
      spawned to grep the submodule will chdir into its gitdir instead of a
      working directory.
      
      In order to override the explicit setting of submodule child process's
      gitdir environment variable (which was introduced in '10f5c526')
      `GIT_DIR_ENVIORMENT` needs to be pushed onto child process's env_array.
      This allows the searching of history from a submodule's gitdir, rather
      than from a working directory.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e6fac7f3
    • B
      grep: enable recurse-submodules to work on <tree> objects · 74ed4371
      Brandon Williams 提交于
      Teach grep to recursively search in submodules when provided with a
      <tree> object. This allows grep to search a submodule based on the state
      of the submodule that is present in a commit of the super project.
      
      When grep is provided with a <tree> object, the name of the object is
      prefixed to all output.  In order to provide uniformity of output
      between the parent and child processes the option `--parent-basename`
      has been added so that the child can preface all of it's output with the
      name of the parent's object instead of the name of the commit SHA1 of
      the submodule. This changes output from the command
      `git grep -e. -l --recurse-submodules HEAD` from:
      
            HEAD:file
            <commit sha1 of submodule>:sub/file
      
      to:
      
            HEAD:file
            HEAD:sub/file
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      74ed4371
    • B
      grep: optionally recurse into submodules · 0281e487
      Brandon Williams 提交于
      Allow grep to recognize submodules and recursively search for patterns in
      each submodule.  This is done by forking off a process to recursively
      call grep on each submodule.  The top level --super-prefix option is
      used to pass a path to the submodule which can in turn be used to
      prepend to output or in pathspec matching logic.
      
      Recursion only occurs for submodules which have been initialized and
      checked out by the parent project.  If a submodule hasn't been
      initialized and checked out it is simply skipped.
      
      In order to support the existing multi-threading infrastructure in grep,
      output from each child process is captured in a strbuf so that it can be
      later printed to the console in an ordered fashion.
      
      To limit the number of theads that are created, each child process has
      half the number of threads as its parents (minimum of 1), otherwise we
      potentailly have a fork-bomb.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0281e487
  23. 08 9月, 2016 1 次提交
  24. 02 7月, 2016 1 次提交
    • C
      grep: fix grepping for "intent to add" files · b8e47d1a
      Charles Bailey 提交于
      This reverts commit 4d552005 (grep: make it clear i-t-a entries are
      ignored, 2015-12-27) and adds an alternative fix to maintain the -L
      --cached behavior.
      
      4d552005 caused 'git grep' to no longer find matches in new files in
      the working tree where the corresponding index entry had the "intent to
      add" bit set, despite the fact that these files are tracked.
      
      The content in the index of a file for which the "intent to add" bit is
      set is considered indeterminate and not empty. For most grep queries we
      want these to behave the same, however for -L --cached (files without a
      match) we don't want to respond positively for "intent to add" files as
      their contents are indeterminate. This is in contrast to files with
      empty contents in the index (no lines implies no matches for any grep
      query expression) which should be reported in the output of a grep -L
      --cached invocation.
      
      Add tests to cover this case and a few related cases which previously
      lacked coverage.
      Helped-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NCharles Bailey <cbailey32@bloomberg.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b8e47d1a
  25. 26 4月, 2016 1 次提交