1. 19 4月, 2017 1 次提交
  2. 30 3月, 2017 1 次提交
  3. 17 3月, 2017 2 次提交
  4. 26 1月, 2017 1 次提交
    • S
      unpack-trees: support super-prefix option · 3d415425
      Stefan Beller 提交于
      In the future we want to support working tree operations within submodules,
      e.g. "git checkout --recurse-submodules", which will update the submodule
      to the commit as recorded in its superproject. In the submodule the
      unpack-tree operation is carried out as usual, but the reporting to the
      user needs to prefix any path with the superproject. The mechanism for
      this is the super-prefix. (see 74866d75, git: make super-prefix option)
      
      Add support for the super-prefix option for commands that unpack trees
      by wrapping any path output in unpacking trees in the newly introduced
      super_prefixed function. This new function prefixes any path with the
      super-prefix if there is one.  Assuming the submodule case doesn't happen
      in the majority of the cases, we'd want to have a fast behavior for no
      super prefix, i.e. no reallocation/copying, but just returning path.
      
      Another aspect of introducing the `super_prefixed` function is to consider
      who owns the memory and if this is the right place where the path gets
      modified. As the super prefix ought to change the output behavior only and
      not the actual unpack tree part, it is fine to be that late in the line.
      As we get passed in 'const char *path', we cannot change the path itself,
      which means in case of a super prefix we have to copy over the path.
      We need two static buffers in that function as the error messages
      contain at most two paths.
      
      For testing purposes enable it in read-tree, which has no output
      of paths other than an unpack-trees.c. These are all converted in
      this patch.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3d415425
  5. 11 1月, 2017 3 次提交
  6. 06 12月, 2016 1 次提交
  7. 23 9月, 2016 1 次提交
  8. 14 9月, 2016 1 次提交
  9. 09 9月, 2016 1 次提交
  10. 08 9月, 2016 1 次提交
  11. 27 6月, 2016 1 次提交
  12. 13 5月, 2016 1 次提交
  13. 10 5月, 2016 1 次提交
  14. 26 4月, 2016 1 次提交
  15. 13 4月, 2016 1 次提交
  16. 23 1月, 2016 1 次提交
  17. 06 1月, 2016 1 次提交
    • D
      do_compare_entry: use already-computed path · d9c2bd56
      David Turner 提交于
      In traverse_trees, we generate the complete traverse path for a
      traverse_info.  Later, in do_compare_entry, we used to go do a bunch
      of work to compare the traverse_info to a cache_entry's name without
      computing that path.  But since we already have that path, we don't
      need to do all that work.  Instead, we can just put the generated
      path into the traverse_info, and do the comparison more directly.
      
      We copy the path because prune_traversal might mutate `base`. This
      doesn't happen in any codepaths where do_compare_entry is called,
      but it's better to be safe.
      
      This makes git checkout much faster -- about 25% on Twitter's
      monorepo.  Deeper directory trees are likely to benefit more than
      shallower ones.
      Signed-off-by: NDavid Turner <dturner@twopensource.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d9c2bd56
  18. 26 9月, 2015 1 次提交
  19. 04 9月, 2015 1 次提交
    • J
      verify_absent: allow filenames longer than PATH_MAX · f514ef97
      Jeff King 提交于
      When unpack-trees wants to know whether a path will
      overwrite anything in the working tree, we use lstat() to
      see if there is anything there. But if we are going to write
      "foo/bar", we can't just lstat("foo/bar"); we need to look
      for leading prefixes (e.g., "foo"). So we use the lstat cache
      to find the length of the leading prefix, and copy the
      filename up to that length into a temporary buffer (since
      the original name is const, we cannot just stick a NUL in
      it).
      
      The copy we make goes into a PATH_MAX-sized buffer, which
      will overflow if the prefix is longer than PATH_MAX. How
      this happens is a little tricky, since in theory PATH_MAX is
      the biggest path we will have read from the filesystem. But
      this can happen if:
      
        - the compiled-in PATH_MAX does not accurately reflect
          what the filesystem is capable of
      
        - the leading prefix is not _quite_ what is on disk; it
          contains the next element from the name we are checking.
          So if we want to write "aaa/bbb/ccc/ddd" and "aaa/bbb"
          exists, the prefix of interest is "aaa/bbb/ccc". If
          "aaa/bbb" approaches PATH_MAX, then "ccc" can overflow
          it.
      
      So this can be triggered, but it's hard to do. In
      particular, you cannot just "git clone" a bogus repo. The
      verify_absent checks happen before unpack-trees writes
      anything to the filesystem, so there are never any leading
      prefixes during the initial checkout, and the bug doesn't
      trigger. And by definition, these files are larger than
      PATH_MAX, so writing them will fail, and clone will
      complain (though it may write a partial path, which will
      cause a subsequent "git checkout" to hit the bug).
      
      We can fix it by creating the temporary path on the heap.
      The extra malloc overhead is not important, as we are
      already making at least one stat() call (and probably more
      for the prefix discovery).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f514ef97
  20. 11 8月, 2015 1 次提交
    • J
      prefer git_pathdup to git_path in some possibly-dangerous cases · fcd12db6
      Jeff King 提交于
      Because git_path uses a static buffer that is shared with
      calls to git_path, mkpath, etc, it can be dangerous to
      assign the result to a variable or pass it to a non-trivial
      function. The value may change unexpectedly due to other
      calls.
      
      None of the cases changed here has a known bug, but they're
      worth converting away from git_path because:
      
        1. It's easy to use git_pathdup in these cases.
      
        2. They use constructs (like assignment) that make it
           hard to tell whether they're safe or not.
      
      The extra malloc overhead should be trivial, as an
      allocation should be an order of magnitude cheaper than a
      system call (which we are clearly about to make, since we
      are constructing a filename). The real cost is that we must
      remember to free the result.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fcd12db6
  21. 29 7月, 2015 1 次提交
  22. 22 7月, 2015 1 次提交
    • D
      unpack-trees: don't update files with CE_WT_REMOVE set · 7d782416
      David Turner 提交于
      Don't update files in the worktree from cache entries which are
      flagged with CE_WT_REMOVE.
      
      When a user does a sparse checkout, git removes files that are
      marked with CE_WT_REMOVE (because they are out-of-scope for the
      sparse checkout). If those files are also marked CE_UPDATE (for
      instance, because they differ in the branch that is being checked
      out and the outgoing branch), git would previously recreate them.
      This patch prevents them from being recreated.
      
      These erroneously-created files would also interfere with merges,
      causing pre-merge revisions of out-of-scope files to appear in the
      worktree.
      
      apply_sparse_checkout() is the function where all "action"
      manipulation (add, delete, update files..) for sparse checkout
      occurs; it should not ask to delete and update both at the same
      time.
      Signed-off-by: NAnatole Shaw <git-devel@omni.poc.net>
      Signed-off-by: NDavid Turner <dturner@twopensource.com>
      Helped-by: NDuy Nguyen <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7d782416
  23. 13 3月, 2015 1 次提交
    • N
      untracked cache: invalidate at index addition or removal · e931371a
      Nguyễn Thái Ngọc Duy 提交于
      Ideally we should implement untracked_cache_remove_from_index() and
      untracked_cache_add_to_index() so that they update untracked cache
      right away instead of invalidating it and wait for read_directory()
      next time to deal with it. But that may need some more work in
      unpack-trees.c. So stay simple as the first step.
      
      The new call in add_index_entry_with_check() may look strange because
      new calls usually stay close to cache_tree_invalidate_path(). We do it
      a bit later than c_t_i_p() in this function because if it's about
      replacing the entry with the same name, we don't care (but cache-tree
      does).
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e931371a
  24. 18 12月, 2014 1 次提交
  25. 18 11月, 2014 1 次提交
  26. 26 8月, 2014 1 次提交
    • J
      checkout -m: attempt merge when deletion of path was staged · 6a143aa2
      Jonathan Nieder 提交于
      twoway_merge() is missing an o->gently check in the case where a file
      that needs to be modified is missing from the index but present in the
      old and new trees.  As a result, in this case 'git checkout -m' errors
      out instead of trying to perform a merge.
      
      Fix it by checking o->gently.  While at it, inline the o->gently check
      into reject_merge to prevent future call sites from making the same
      mistake.
      
      Noticed by code inspection.  The test for the motivating case was
      added by JC.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6a143aa2
  27. 14 8月, 2014 2 次提交
    • J
      unpack-trees: use 'cuddled' style for if-else cascade · 6c1db1b3
      Jonathan Nieder 提交于
      Match the predominant style in git by following K&R style for if/else
      cascades.  Documentation/CodingStyle from linux.git explains:
      
        Note that the closing brace is empty on a line of its own, _except_ in
        the cases where it is followed by a continuation of the same statement,
        ie a "while" in a do-statement or an "else" in an if-statement, like
        this:
      
      	if (x == y) {
      		..
      	} else if (x > y) {
      		...
      	} else {
      		....
      	}
      
        Rationale: K&R.
      
        Also, note that this brace-placement also minimizes the number of empty
        (or almost empty) lines, without any loss of readability.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6c1db1b3
    • S
      unpack-trees: simplify 'all other failures' case · 0ecd180a
      Stefan Beller 提交于
      In the 'if (current)' block of twoway_merge, we handle the boring
      errors by checking if the entry from the old tree, current index, and
      new tree are present, to get a pathname for the error message from one
      of them:
      
      	if (oldtree)
      		return o->gently ? -1 : reject_merge(oldtree, o);
      	if (current)
      		return o->gently ? -1 : reject_merge(current, o);
      	if (newtree)
      		return o->gently ? -1 : reject_merge(newtree, o);
      	return -1;
      
      Since this is guarded by 'if (current)', the second test is guaranteed
      to succeed.  Moreover, any of the three entries, if present, would
      have the same path because there is no rename detection in this code
      path.   Even if some day in the future the entries' paths differ, the
      'current' path used in the index and worktree would presumably be the
      most recognizable for the end user.
      
      Simplify by just using 'current'.
      
      Noticed by coverity, Id:290002
      Signed-off-by: NStefan Beller <stefanbeller@gmail.com>
      Improved-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0ecd180a
  28. 21 6月, 2014 1 次提交
    • J
      cleanup duplicate name_compare() functions · ccdd4a0f
      Jeremiah Mahler 提交于
      We often represent our strings as a counted string, i.e. a pair of
      the pointer to the beginning of the string and its length, and the
      string may not be NUL terminated to that length.
      
      To compare a pair of such counted strings, unpack-trees.c and
      read-cache.c implement their own name_compare() functions
      identically.  In addition, the cache_name_compare() function in
      read-cache.c is nearly identical.  The only difference is when one
      string is the prefix of the other string, in which case
      name_compare() returns -1/+1 to show which one is longer, and
      cache_name_compare() returns the difference of the lengths to show
      the same information.
      
      Unify these three functions by using the implementation from
      cache_name_compare().  This does not make any difference to the
      existing and future callers, as they must be paying attention only
      to the sign of the returned value (and not the magnitude) because
      the original implementations of these two functions return values
      returned by memcmp(3) when the one string is not a prefix of the
      other string, and the only thing memcmp(3) guarantees its callers is
      the sign of the returned value, not the magnitude.
      Signed-off-by: NJeremiah Mahler <jmmahler@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ccdd4a0f
  29. 20 6月, 2014 1 次提交
    • J
      use xstrfmt in favor of manual size calculations · fa3f60b7
      Jeff King 提交于
      In many parts of the code, we do an ugly and error-prone
      malloc like:
      
        const char *fmt = "something %s";
        buf = xmalloc(strlen(foo) + 10 + 1);
        sprintf(buf, fmt, foo);
      
      This makes the code brittle, and if we ever get the
      allocation wrong, is a potential heap overflow. Let's
      instead favor xstrfmt, which handles the allocation
      automatically, and makes the code shorter and more readable.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fa3f60b7
  30. 14 6月, 2014 6 次提交
  31. 25 2月, 2014 1 次提交