1. 14 3月, 2010 1 次提交
    • J
      dir: fix COLLECT_IGNORED on excluded prefixes · 29209cbe
      Jeff King 提交于
      As we walk the directory tree, if we see an ignored path, we
      want to add it to the ignored list only if it matches any
      pathspec that we were given. We used to check for the
      pathspec to appear explicitly. E.g., if we see "subdir/file"
      and it is excluded, we check to see if we have "subdir/file"
      in our pathspec.
      
      However, this interacts badly with the optimization to avoid
      recursing into ignored subdirectories. If "subdir" as a
      whole is ignored, then we never recurse, and consider only
      whether "subdir" itself is in our pathspec.  It would not
      match a pathspec of "subdir/file" explicitly, even though it
      is the reason that subdir/file would be excluded.
      
      This manifests itself to the user as "git add subdir/file"
      failing to correctly note that the pathspec was ignored.
      
      This patch extends the in_pathspec logic to include prefix
      directory case.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      29209cbe
  2. 19 2月, 2010 1 次提交
  3. 21 1月, 2010 1 次提交
    • N
      Fix memory corruption when .gitignore does not end by \n · 45d76f17
      Nguyễn Thái Ngọc Duy 提交于
      Commit b5041c5f (Avoid writing to buffer in add_excludes_from_file_1())
      tried not to append '\n' at the end because the next commit
      may return a buffer that does not have extra space for that.
      
      Unfortunately it left this assignment in the loop:
      
        buf[i - (i && buf[i-1] == '\r')] = 0;
      
      that can corrupt memory if "buf" is not '\n' terminated. But even if
      it does not corrupt memory, the last line would not be
      NULL-terminated, leading to errors later inside add_exclude().
      
      This patch fixes it by reverting the faulty commit and make
      sure "buf" is always \n terminated.
      
      While at it, free unused memory properly.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      45d76f17
  4. 09 1月, 2010 3 次提交
    • J
      ls-files: fix overeager pathspec optimization · 48ffef96
      Junio C Hamano 提交于
      Given pathspecs that share a common prefix, ls-files optimized its call
      into recursive directory reader by starting at the common prefix
      directory.
      
      If you have a directory "t" with an untracked file "t/junk" in it, but the
      top-level .gitignore file told us to ignore "t/", this resulted in:
      
          $ git ls-files -o --exclude-standard
          $ git ls-files -o --exclude-standard t/
          t/junk
          $ git ls-files -o --exclude-standard t/junk
          t/junk
          $ cd t && git ls-files -o --exclude-standard
          junk
      
      We could argue that you are overriding the ignore file by giving a
      patchspec that matches or being in that directory, but it is somewhat
      unexpected.  Worse yet, these behave differently:
      
          $ git ls-files -o --exclude-standard t/ .
          $ git ls-files -o --exclude-standard t/
          t/junk
      
      This patch changes the optimization so that it notices when the common
      prefix directory that it starts reading from is an ignored one.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      48ffef96
    • J
      read_directory(): further split treat_path() · 16e2cfa9
      Junio C Hamano 提交于
      The next caller I'll be adding won't have an access to struct dirent
      because it won't be reading from a directory stream.  Split the main
      part of the function further into a separate function to make it usable
      by a caller without passing a dirent as long as it knows what type is
      feeding the function.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      16e2cfa9
    • J
      read_directory_recursive(): refactor handling of a single path into a separate function · 53cc5356
      Junio C Hamano 提交于
      Primarily because I want to reuse it in a separate function later,
      but this de-dents a huge function by one tabstop which by itself is
      an improvement as well.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      53cc5356
  5. 24 8月, 2009 4 次提交
  6. 30 7月, 2009 1 次提交
  7. 10 7月, 2009 1 次提交
  8. 09 7月, 2009 3 次提交
  9. 28 6月, 2009 1 次提交
  10. 01 6月, 2009 1 次提交
    • J
      git-add: no need for -f when resolving a conflict in already tracked path · 6e4f981f
      Jeff King 提交于
      When a path F that matches ignore pattern has a conflict, "git add F"
      insisted the -f option be given, which did not make sense.  It would have
      required -f when the path was originally added, but when resolving a
      conflict, it already is tracked.
      
      So this should work (and does):
      
        $ echo file >.gitignore
        $ echo content >file
        $ git add -f file ;# need -f because we are adding new path
        $ echo more content >>file
        $ git add file ;# don't need -f; it is not actually an "other" file
      
      This is handled under the hood by the COLLECT_IGNORED option to
      read_directory. When that code finds an ignored file, it checks the
      index to make sure it is not actually a tracked file. However, the test
      it uses does not take into account unmerged entries, and considers them
      to still be ignored. "git ls-files" uses a more elaborate test and gets
      the right answer and the same test should be used here.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6e4f981f
  11. 17 5月, 2009 1 次提交
    • L
      dir.c: clean up handling of 'path' parameter in read_directory_recursive() · da4b3e8c
      Linus Torvalds 提交于
      Right now we pass two different pathnames ('path' and 'base') down to
      read_directory_recursive(), and the only real reason for that is that we
      want to allow an empty 'base' parameter, but when we do so, we need the
      pathname to "opendir()" to be "." rather than the empty string.
      
      And rather than handle that confusion in the caller, we can just fix
      read_directory_recursive() to handle the case of an empty path itself,
      by just passing opendir() a "." ourselves if the path is empty.
      
      This would allow us to then drop one of the pathnames entirely from the
      calling convention, but rather than do that, we'll start separating them
      out as a "filesystem pathname" (the one we use for filesystem accesses)
      and a "git internal base name" (which is the name that we use for git
      internally).
      
      That will eventually allow us to do things like handle different
      encodings (eg the filesystem pathnames might be Latin1, while git itself
      would use UTF-8 for filename information).
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      da4b3e8c
  12. 06 5月, 2009 1 次提交
  13. 02 5月, 2009 1 次提交
  14. 19 2月, 2009 1 次提交
  15. 13 2月, 2009 1 次提交
    • F
      Support "\" in non-wildcard exclusion entries · dd482eea
      Finn Arne Gangstad 提交于
      "\" was treated differently in exclude rules depending on whether a
      wildcard match was done. For wildcard rules, "\" was de-escaped in
      fnmatch, but this was not done for other rules since they used strcmp
      instead.  A file named "#foo" would not be excluded by "\#foo", but would
      be excluded by "\#foo*".
      
      We now treat all rules with "\" as wildcard rules.
      
      Another solution could be to de-escape all non-wildcard rules as we
      read them, but we would have to do the de-escaping exactly as fnmatch
      does it to avoid inconsistencies.
      Signed-off-by: NFinn Arne Gangstad <finnag@pvv.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dd482eea
  16. 10 2月, 2009 1 次提交
  17. 18 1月, 2009 1 次提交
    • R
      Change NUL char handling of isspecial() · 8cc32992
      René Scharfe 提交于
      Replace isspecial() by the new macro is_glob_special(), which is more,
      well, specialized.  The former included the NUL char in its character
      class, while the letter only included characters that are special to
      file name globbing.
      
      The new name contains underscores because they enhance readability
      considerably now that it's made up of three words.  Renaming the
      function is necessary to document its changed scope.
      
      The call sites of isspecial() are updated to check explicitly for NUL.
      Signed-off-by: NRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8cc32992
  18. 15 1月, 2009 2 次提交
  19. 12 1月, 2009 2 次提交
  20. 03 10月, 2008 1 次提交
  21. 29 9月, 2008 1 次提交
  22. 29 8月, 2008 1 次提交
  23. 14 8月, 2008 1 次提交
  24. 05 8月, 2008 1 次提交
  25. 27 4月, 2008 1 次提交
    • L
      Optimize match_pathspec() to avoid fnmatch() · 88ea8112
      Linus Torvalds 提交于
      "git add *" is actually fundamentally different from "git add .", and
      yeah, you should generally use the latter.
      
      The reason? The argument list is actually something different from what
      you think it is. For git, it's a "pathspec", so what actualy happens is
      that in *both* cases, it will really traverse the whole tree, and then
      match every file it finds against the pathspec.
      
      So think of the arguments not as a file list, but as a random bunch of
      patterns to match against the files you have!
      
      Which is why the cost is actually approximately O(n*m), where "n" is the
      size of the working tree, and "m" is the number of pathspecs.
      
      So the reason "git add ." is fast is actually that "m" in that case is
      just 1 (just one trivial pattern), and then "git add *" is slow because
      "m" is large (lots of complicated patterns). In both cases, 'n' is the
      same (== the whole set of files in your working tree).
      
      Anyway, here's a trivial patch that doesn't change this fundamental fact,
      but that avoids doing anything *expensive* until we've done some cheap
      initial tests. It may or may not help your test-case, but it's pretty
      simple and it matches the other git optimizations in this area (ie
      "conceptually handle the general case, but optimize the simple cases where
      we can exit early")
      
      Notice how this patch doesn' actually change the fundamental O(n^2)
      behaviour, but it makes it much cheaper by generally avoiding the
      expensive 'fnmatch' and 'strlen/strncmp' when they are obviously not
      needed.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      88ea8112
  26. 15 4月, 2008 1 次提交
  27. 09 4月, 2008 2 次提交
  28. 23 2月, 2008 1 次提交
    • J
      Avoid unnecessary "if-before-free" tests. · 8e0f7003
      Jim Meyering 提交于
      This change removes all obvious useless if-before-free tests.
      E.g., it replaces code like this:
      
              if (some_expression)
                      free (some_expression);
      
      with the now-equivalent:
      
              free (some_expression);
      
      It is equivalent not just because POSIX has required free(NULL)
      to work for a long time, but simply because it has worked for
      so long that no reasonable porting target fails the test.
      Here's some evidence from nearly 1.5 years ago:
      
          http://www.winehq.org/pipermail/wine-patches/2006-October/031544.html
      
      FYI, the change below was prepared by running the following:
      
        git ls-files -z | xargs -0 \
        perl -0x3b -pi -e \
          's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\(\s*\1\s*\))/$2/s'
      
      Note however, that it doesn't handle brace-enclosed blocks like
      "if (x) { free (x); }".  But that's ok, since there were none like
      that in git sources.
      
      Beware: if you do use the above snippet, note that it can
      produce syntactically invalid C code.  That happens when the
      affected "if"-statement has a matching "else".
      E.g., it would transform this
      
        if (x)
          free (x);
        else
          foo ();
      
      into this:
      
        free (x);
        else
          foo ();
      
      There were none of those here, either.
      
      If you're interested in automating detection of the useless
      tests, you might like the useless-if-before-free script in gnulib:
      [it *does* detect brace-enclosed free statements, and has a --name=S
       option to make it detect free-like functions with different names]
      
        http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=build-aux/useless-if-before-free
      
      Addendum:
        Remove one more (in imap-send.c), spotted by Jean-Luc Herren <jlh@gmx.ch>.
      Signed-off-by: NJim Meyering <meyering@redhat.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8e0f7003
  29. 05 2月, 2008 2 次提交
    • J
      gitignore: lazily find dtype · 6831a88a
      Junio C Hamano 提交于
      When we process "foo/" entries in gitignore files on a system
      that does not have d_type member in "struct dirent", the earlier
      implementation ran lstat(2) separately when matching with
      entries that came from the command line, in-tree .gitignore
      files, and $GIT_DIR/info/excludes file.
      
      This optimizes it by delaying the lstat(2) call until it becomes
      absolutely necessary.
      
      The initial idea for this change was by Jeff King, but I
      optimized it further to pass pointers to around.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6831a88a
    • J
      gitignore(5): Allow "foo/" in ignore list to match directory "foo" · d6b8fc30
      Junio C Hamano 提交于
      A pattern "foo/" in the exclude list did not match directory
      "foo", but a pattern "foo" did.  This attempts to extend the
      exclude mechanism so that it would while not matching a regular
      file or a symbolic link "foo".  In order to differentiate a
      directory and non directory, this passes down the type of path
      being checked to excluded() function.
      
      A downside is that the recursive directory walk may need to run
      lstat(2) more often on systems whose "struct dirent" do not give
      the type of the entry; earlier it did not have to do so for an
      excluded path, but we now need to figure out if a path is a
      directory before deciding to exclude it.  This is especially bad
      because an idea similar to the earlier CE_UPTODATE optimization
      to reduce number of lstat(2) calls would by definition not apply
      to the codepaths involved, as (1) directories will not be
      registered in the index, and (2) excluded paths will not be in
      the index anyway.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d6b8fc30