1. 06 10月, 2008 1 次提交
    • D
      make prefix_path() never return NULL · 62525ef7
      Dmitry Potapov 提交于
      There are 9 places where prefix_path is called, and only in one of
      them the returned pointer was checked to be non-zero and only to
      call exit(128) as it is usually done by die(). In other 8 places,
      the returned value was not checked and it caused SIGSEGV when a
      path outside of the working tree was used. For instance, running
        git update-index --add /some/path/outside
      caused SIGSEGV.
      
      This patch changes prefix_path() to die if the path is outside of
      the repository, so it never returns NULL.
      Signed-off-by: NDmitry Potapov <dpotapov@gmail.com>
      Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
      62525ef7
  2. 31 8月, 2008 1 次提交
  3. 23 6月, 2008 2 次提交
    • J
      Windows: Treat Windows style path names. · 25fe217b
      Johannes Sixt 提交于
      GIT's guts work with a forward slash as a path separators. We do not change
      that. Rather we make sure that only "normalized" paths enter the depths
      of the machinery.
      
      We have to translate backslashes to forward slashes in the prefix and in
      command line arguments. Fortunately, all of them are passed through
      functions in setup.c.
      
      A macro has_dos_drive_path() is defined that checks whether a path begins
      with a drive letter+colon combination. This predicate is always false on
      Unix. Another macro is_dir_sep() abstracts that a backslash is also a
      directory separator on Windows.
      Signed-off-by: NJohannes Sixt <johannes.sixt@telecom.at>
      25fe217b
    • J
      setup.c: Prepare for Windows directory separators. · 4cd148d8
      Johannes Sixt 提交于
      This turns two switch/case statements into an if-else-if cascade because
      we later do not want to have
      
              case '/':
          #ifdef __MINGW32__
              case '\\':
          #endif
      
      but use a predicate is_dir_sep(foo) in order to check for the directory
      separator.
      Signed-off-by: NJohannes Sixt <johannes.sixt@telecom.at>
      4cd148d8
  4. 20 6月, 2008 1 次提交
    • L
      Make git_dir a path relative to work_tree in setup_work_tree() · 044bbbcb
      Linus Torvalds 提交于
      Once we find the absolute paths for git_dir and work_tree, we can make
      git_dir a relative path since we know pwd will be work_tree. This should
      save the kernel some time traversing the path to work_tree all the time
      if git_dir is inside work_tree.
      
      Daniel's patch didn't apply for me as-is, so I recreated it with some
      differences, and here are the numbers from ten runs each.
      
      There is some IO for me - probably due to more-or-less random flushing of
      the journal - so the variation is bigger than I'd like, but whatever:
      
      	Before:
      		real    0m8.135s
      		real    0m7.933s
      		real    0m8.080s
      		real    0m7.954s
      		real    0m7.949s
      		real    0m8.112s
      		real    0m7.934s
      		real    0m8.059s
      		real    0m7.979s
      		real    0m8.038s
      
      	After:
      		real    0m7.685s
      		real    0m7.968s
      		real    0m7.703s
      		real    0m7.850s
      		real    0m7.995s
      		real    0m7.817s
      		real    0m7.963s
      		real    0m7.955s
      		real    0m7.848s
      		real    0m7.969s
      
      Now, going by "best of ten" (on the assumption that the longer numbers
      are all due to IO), I'm saying a 7.933s -> 7.685s reduction, and it does
      seem to be outside of the noise (ie the "after" case never broke 8s, while
      the "before" case did so half the time).
      
      So looks like about 3% to me.
      
      Doing it for a slightly smaller test-case (just the "arch" subdirectory)
      gets more stable numbers probably due to not filling the journal with
      metadata updates, so we have:
      
      	Before:
      		real    0m1.633s
      		real    0m1.633s
      		real    0m1.633s
      		real    0m1.632s
      		real    0m1.632s
      		real    0m1.630s
      		real    0m1.634s
      		real    0m1.631s
      		real    0m1.632s
      		real    0m1.632s
      
      	After:
      		real    0m1.610s
      		real    0m1.609s
      		real    0m1.610s
      		real    0m1.608s
      		real    0m1.607s
      		real    0m1.610s
      		real    0m1.609s
      		real    0m1.611s
      		real    0m1.608s
      		real    0m1.611s
      
      where I'ld just take the averages and say 1.632 vs 1.610, which is just
      over 1% peformance improvement.
      
      So it's not in the noise, but it's not as big as I initially thought and
      measured.
      
      (That said, it obviously depends on how deep the working directory path is
      too, and whether it is behind NFS or something else that might need to
      cause more work to look up).
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      044bbbcb
  5. 24 5月, 2008 2 次提交
  6. 15 5月, 2008 1 次提交
  7. 17 4月, 2008 1 次提交
    • H
      Make core.sharedRepository more generic · 06cbe855
      Heikki Orsila 提交于
      git init --shared=0xxx, where '0xxx' is an octal number, will create
      a repository with file modes set to '0xxx'. Users with a safe umask
      value (0077) can use this option to force file modes. For example,
      '0640' is a group-readable but not group-writable regardless of
      user's umask value. Values compatible with old Git versions are written
      as they were before, for compatibility reasons. That is, "1" for
      "group" and "2" for "everybody".
      
      "git config core.sharedRepository 0xxx" is also handled.
      Signed-off-by: NHeikki Orsila <heikki.orsila@iki.fi>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      06cbe855
  8. 09 4月, 2008 1 次提交
  9. 27 3月, 2008 1 次提交
  10. 07 3月, 2008 1 次提交
    • J
      get_pathspec(): die when an out-of-tree path is given · 3296766e
      Junio C Hamano 提交于
      An earlier commit d089ebaa (setup: sanitize absolute and funny paths) made
      get_pathspec() aware of absolute paths, but with a botched interface that
      forced the callers to count the resulting pathspecs in order to detect
      an error of giving a path that is outside the work tree.
      
      This fixes it, by dying inside the function.
      
      We had ls-tree test that relied on a misfeature in the original
      implementation of its pathspec handling.  Leading slashes were silently
      removed from them.  However we allow giving absolute pathnames (people
      want to cut and paste from elsewhere) that are inside work tree these
      days, so a pathspec that begin with slash _should_ be treated as a full
      path.  The test is adjusted to match the updated rule for get_pathspec().
      
      Earlier I mistook three tests given by Robin that they should succeed, but
      these are attempts to add path outside work tree, which should fail
      loudly.  These tests also have been fixed.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3296766e
  11. 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
  12. 21 2月, 2008 1 次提交
  13. 12 2月, 2008 1 次提交
  14. 05 2月, 2008 1 次提交
    • J
      setup: sanitize absolute and funny paths in get_pathspec() · d089ebaa
      Junio C Hamano 提交于
      The prefix_path() function called from get_pathspec() is
      responsible for translating list of user-supplied pathspecs to
      list of pathspecs that is relative to the root of the work
      tree.  When working inside a subdirectory, the user-supplied
      pathspecs are taken to be relative to the current subdirectory.
      
      Among special path components in pathspecs, we used to accept
      and interpret only "." ("the directory", meaning a no-op) and
      ".."  ("up one level") at the beginning.  Everything else was
      passed through as-is.
      
      For example, if you are in Documentation/ directory of the
      project, you can name Documentation/howto/maintain-git.txt as:
      
          howto/maintain-git.txt
          ../Documentation/howto/maitain-git.txt
          ../././Documentation/howto/maitain-git.txt
      
      but not as:
      
          howto/./maintain-git.txt
          $(pwd)/howto/maintain-git.txt
      
      This patch updates prefix_path() in several ways:
      
       - If the pathspec is not absolute, prefix (i.e. the current
         subdirectory relative to the root of the work tree, with
         terminating slash, if not empty) and the pathspec is
         concatenated first and used in the next step.  Otherwise,
         that absolute pathspec is used in the next step.
      
       - Then special path components "." (no-op) and ".." (up one
         level) are interpreted to simplify the path.  It is an error
         to have too many ".." to cause the intermediate result to
         step outside of the input to this step.
      
       - If the original pathspec was not absolute, the result from
         the previous step is the resulting "sanitized" pathspec.
         Otherwise, the result from the previous step is still
         absolute, and it is an error if it does not begin with the
         directory that corresponds to the root of the work tree.  The
         directory is stripped away from the result and is returned.
      
       - In any case, the resulting pathspec in the array
         get_pathspec() returns omit the ones that caused errors.
      
      With this patch, the last two examples also behave as expected.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d089ebaa
  15. 04 1月, 2008 1 次提交
  16. 09 12月, 2007 1 次提交
  17. 06 12月, 2007 1 次提交
  18. 01 12月, 2007 1 次提交
  19. 27 11月, 2007 1 次提交
  20. 10 11月, 2007 1 次提交
  21. 09 11月, 2007 1 次提交
  22. 06 11月, 2007 1 次提交
  23. 04 11月, 2007 1 次提交
  24. 17 10月, 2007 1 次提交
  25. 10 8月, 2007 1 次提交
  26. 06 8月, 2007 1 次提交
    • J
      setup.c:verify_non_filename(): don't die unnecessarily while disambiguating · 33a798c8
      Junio C Hamano 提交于
      If you have a working tree _file_ "foo", attempt to refer to a
      branch "foo/bar" without -- to disambiguate, like this:
      
      	$ git log foo/bar
      
      tried to make sure that foo/bar cannot be naming a working tree
      file "foo/bar" (in which case we would say "which one do you
      want?  A rev or a working tree file?  clarify with -- please").
      We run lstat("foo/bar") to check that.  If it does not succeed,
      there is no ambiguity.
      
      That is good.  But we also checked the error status for the
      lstat() and expected it to fail with ENOENT.  In this particular
      case, however, it fails with ENOTDIR.  That should be treated as
      "expected error" as well.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      33a798c8
  27. 03 8月, 2007 1 次提交
  28. 01 8月, 2007 1 次提交
    • J
      Clean up work-tree handling · e90fdc39
      Johannes Schindelin 提交于
      The old version of work-tree support was an unholy mess, barely readable,
      and not to the point.
      
      For example, why do you have to provide a worktree, when it is not used?
      As in "git status".  Now it works.
      
      Another riddle was: if you can have work trees inside the git dir, why
      are some programs complaining that they need a work tree?
      
      IOW it is allowed to call
      
      	$ git --git-dir=../ --work-tree=. bla
      
      when you really want to.  In this case, you are both in the git directory
      and in the working tree.  So, programs have to actually test for the right
      thing, namely if they are inside a working tree, and not if they are
      inside a git directory.
      
      Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was
      specified, unless there is a repository in the current working directory.
      It does now.
      
      The logic to determine if a repository is bare, or has a work tree
      (tertium non datur), is this:
      
      --work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true,
      which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR
      ends in /.git, which overrides the directory in which .git/ was found.
      
      In related news, a long standing bug was fixed: when in .git/bla/x.git/,
      which is a bare repository, git formerly assumed ../.. to be the
      appropriate git dir.  This problem was reported by Shawn Pearce to have
      caused much pain, where a colleague mistakenly ran "git init" in "/" a
      long time ago, and bare repositories just would not work.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e90fdc39
  29. 31 7月, 2007 1 次提交
  30. 12 7月, 2007 1 次提交
  31. 05 7月, 2007 1 次提交
    • J
      Do not check if getcwd() result begins with a slash. · f66a4d68
      Junio C Hamano 提交于
      In user space, and for getcwd(), the check to see if the
      resulting path begins with a '/' does not make sense.  This is
      merely a mistake by Linus who is so used to code for the kernel,
      where a d_path() return value pathname can be either a real
      path, or something like "pipe:[8003]", and the difference is the
      '/' at the beginning.
      
      Pointed out by Dscho, Matthias Lederhofer and clarified by Linus.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f66a4d68
  32. 07 6月, 2007 4 次提交
    • J
      War on whitespace · a6080a0a
      Junio C Hamano 提交于
      This uses "git-apply --whitespace=strip" to fix whitespace errors that have
      crept in to our source files over time.  There are a few files that need
      to have trailing whitespaces (most notably, test vectors).  The results
      still passes the test, and build result in Documentation/ area is unchanged.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a6080a0a
    • M
      setup_git_directory: fix segfault if repository is found in cwd · f4f51add
      Matthias Lederhofer 提交于
      Additionally there was a similar part calling setenv and getenv
      in the same way which missed a check if getenv succeeded.
      Signed-off-by: NMatthias Lederhofer <matled@gmx.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f4f51add
    • M
      Use new semantics of is_bare/inside_git_dir/inside_work_tree · 7ae3df8c
      Matthias Lederhofer 提交于
      Up to now to check for a working tree this was used:
      	!is_bare && !inside_git_dir
      (the check for bare is redundant because is_inside_git_dir
      returned already 1 for bare repositories).
      Now the check is:
      	inside_work_tree && !inside_git_dir
      Signed-off-by: NMatthias Lederhofer <matled@gmx.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7ae3df8c
    • M
      introduce GIT_WORK_TREE to specify the work tree · 892c41b9
      Matthias Lederhofer 提交于
      setup_gdg is used as abbreviation for setup_git_directory_gently.
      
      The work tree can be specified using the environment variable
      GIT_WORK_TREE and the config option core.worktree (the environment
      variable has precendence over the config option).  Additionally
      there is a command line option --work-tree which sets the
      environment variable.
      
      setup_gdg does the following now:
      
      GIT_DIR unspecified
      repository in .git directory
          parent directory of the .git directory is used as work tree,
          GIT_WORK_TREE is ignored
      
      GIT_DIR unspecified
      repository in cwd
          GIT_DIR is set to cwd
          see the cases with GIT_DIR specified what happens next and
          also see the note below
      
      GIT_DIR specified
      GIT_WORK_TREE/core.worktree unspecified
          cwd is used as work tree
      
      GIT_DIR specified
      GIT_WORK_TREE/core.worktree specified
          the specified work tree is used
      
      Note on the case where GIT_DIR is unspecified and repository is in cwd:
          GIT_WORK_TREE is used but is_inside_git_dir is always true.
          I did it this way because setup_gdg might be called multiple
          times (e.g. when doing alias expansion) and in successive calls
          setup_gdg should do the same thing every time.
      
      Meaning of is_bare/is_inside_work_tree/is_inside_git_dir:
      
      (1) is_bare_repository
          A repository is bare if core.bare is true or core.bare is
          unspecified and the name suggests it is bare (directory not
          named .git).  The bare option disables a few protective
          checks which are useful with a working tree.  Currently
          this changes if a repository is bare:
              updates of HEAD are allowed
              git gc packs the refs
              the reflog is disabled by default
      
      (2) is_inside_work_tree
          True if the cwd is inside the associated working tree (if there
          is one), false otherwise.
      
      (3) is_inside_git_dir
          True if the cwd is inside the git directory, false otherwise.
          Before this patch is_inside_git_dir was always true for bare
          repositories.
      
      When setup_gdg finds a repository git_config(git_default_config) is
      always called.  This ensure that is_bare_repository makes use of
      core.bare and does not guess even though core.bare is specified.
      
      inside_work_tree and inside_git_dir are set if setup_gdg finds a
      repository.  The is_inside_work_tree and is_inside_git_dir functions
      will die if they are called before a successful call to setup_gdg.
      Signed-off-by: NMatthias Lederhofer <matled@gmx.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      892c41b9
  33. 11 3月, 2007 1 次提交
  34. 21 2月, 2007 1 次提交
    • J
      Mechanical conversion to use prefixcmp() · cc44c765
      Junio C Hamano 提交于
      This mechanically converts strncmp() to use prefixcmp(), but only when
      the parameters match specific patterns, so that they can be verified
      easily.  Leftover from this will be fixed in a separate step, including
      idiotic conversions like
      
          if (!strncmp("foo", arg, 3))
      
        =>
      
          if (!(-prefixcmp(arg, "foo")))
      
      This was done by using this script in px.perl
      
         #!/usr/bin/perl -i.bak -p
         if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
                 s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
         }
         if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
                 s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
         }
      
      and running:
      
         $ git grep -l strncmp -- '*.c' | xargs perl px.perl
      Signed-off-by: NJunio C Hamano <junkio@cox.net>
      cc44c765
  35. 21 1月, 2007 1 次提交