1. 26 Jun, 2013 3 commits
    • Jiang Xin's avatar
      write_name{_quoted_relative,}(): remove redundant parameters · e9a820ce
      Jiang Xin authored
      After substitute path_relative() in quote.c with relative_path()
      from path.c, parameters (such as len and prefix_len) are redundant
      in function write_name() and write_name_quoted_relative().  The
      callers have already been audited that the strings they pass are
      properly NUL terminated and the length they give are the length of
      the string (or -1 that asks the length to be counted by the callee).
      Remove these now-redundant parameters.
      Signed-off-by: Jiang Xin's avatarJiang Xin <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
    • Jiang Xin's avatar
      quote_path_relative(): remove redundant parameter · 39598f99
      Jiang Xin authored
      quote_path_relative() used to take a counted string as its parameter
      (the string to be quoted).  With an earlier change, it now uses
      relative_path() that does not take a counted string, and we have
      been passing only the pointer to the string since then.
      Remove the length parameter from quote_path_relative() to show that
      this parameter was redundant.  All the changed lines show that the
      caller passed either -1 (to ask the function run strlen() on the
      string), or the length of the string, so the earlier conversion was
      All the callers of quote_path_relative() that used to take counted string
      have been audited to make sure that they are passing length of the actual
      string (or -1 to ask the callee run strlen())
      Signed-off-by: Jiang Xin's avatarJiang Xin <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
    • Jiang Xin's avatar
      quote.c: substitute path_relative with relative_path · ad66df2d
      Jiang Xin authored
      Substitute the function path_relative in quote.c with the function
      relative_path. Function relative_path can be treated as an enhanced
      and more robust version of path_relative.
      Outputs of path_relative and it's replacement (relative_path) are the
      same for the following cases:
          path      prefix     output of path_relative  output of relative_path
          ========  =========  =======================  =======================
          /a/b/c/   /a/b/      c/                       c/
          /a/b/c    /a/b/      c                        c
          /a/       /a/b/      ../                      ../
          /         /a/b/      ../../                   ../../
          /a/c      /a/b/      ../c                     ../c
          /x/y      /a/b/      ../../x/y                ../../x/y
          a/b/c/    a/b/       c/                       c/
          a/        a/b/       ../                      ../
          x/y       a/b/       ../../x/y                ../../x/y
          /a/b      (empty)    /a/b                     /a/b
          /a/b      (null)     /a/b                     /a/b
          a/b       (empty)    a/b                      a/b
          a/b       (null)     a/b                      a/b
      But if both of the path and the prefix are the same, or the returned
      relative path should be the current directory, the outputs of both
      functions are different. Function relative_path returns "./", while
      function path_relative returns empty string.
          path      prefix     output of path_relative  output of relative_path
          ========  =========  =======================  =======================
          /a/b/     /a/b/      (empty)                  ./
          a/b/      a/b/       (empty)                  ./
          (empty)   (null)     (empty)                  ./
          (empty)   (empty)    (empty)                  ./
      But the callers of path_relative can handle such cases, or never
      encounter this issue at all, because:
       * In function quote_path_relative, if the output of path_relative is
         empty, append "./" to it, like:
             if (!out->len)
                 strbuf_addstr(out, "./");
       * Another caller is write_name_quoted_relative, which is only used
         by builtin/ls-files.c. git-ls-files only show files, so path of
         files will never be identical with the prefix of a directory.
      The following differences show that path_relative does not handle
      extra slashes properly:
          path      prefix     output of path_relative  output of relative_path
          ========  =========  =======================  =======================
          /a//b//c/ //a/b//    ../../../../a//b//c/     c/
          a/b//c    a//b       ../b//c                  c
      And if prefix has no trailing slash, path_relative does not work
      properly either.  But since prefix always has a trailing slash, it's
      not a problem.
          path      prefix     output of path_relative  output of relative_path
          ========  =========  =======================  =======================
          /a/b/c/   /a/b       b/c/                     c/
          /a/b      /a/b       b                        ./
          /a/b/     /a/b       b/                       ./
          /a        /a/b/      ../../a                  ../
          a/b/c/    a/b        b/c/                     c/
          a/b/      a/b        b/                       ./
          a         a/b        ../a                     ../
          x/y       a/b/       ../x/y                   ../../x/y
          a/c       a/b        c                        ../c
          /a/       /a/b       (empty)                  ../
          (empty)   /a/b       ../../                   ./
      One tricky part in this conversion is write_name() function in
      ls-files.c.  It takes a counted string, <name, len>, that is to be
      made relative to <prefix, prefix_len> and then quoted.  Because
      write_name_quoted_relative() still takes these two parameters as
      counted string, but ignores the count and treat these two as
      NUL-terminated strings, this conversion needs to be audited for its
       - For <name, len>, all three callers of write_name() passes a
         NUL-terminated string and its true length, so this patch makes
         "len" unused.
       - For <prefix, prefix_len>, prefix could be a string that is longer
         than empty while prefix_len could be 0 when "--full-name" option
         is used.  This is fixed by checking prefix_len in write_name()
         and calling write_name_quoted_relative() with NULL when
         prefix_len is set to 0.  Again, this makes "prefix_len" given to
         write_name_quoted_relative() unused, without introducing a bug.
      Signed-off-by: Jiang Xin's avatarJiang Xin <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  2. 14 Sep, 2011 1 commit
    • Jeff King's avatar
      quote: provide sq_dequote_to_argv_array · 37e8161a
      Jeff King authored
      This is similar to sq_dequote_to_argv, but more convenient
      if you have an argv_array. It's tempting to just feed the
      components of the argv_array to sq_dequote_to_argv instead,
        1. It wouldn't maintain the NULL-termination invariant
           of argv_array.
        2. It doesn't match the memory ownership policy of
           argv_array (in which each component is free-able, not a
           pointer into a separate buffer).
      Signed-off-by: default avatarJeff King <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  3. 11 Aug, 2011 1 commit
    • Clemens Buchacher's avatar
      ls-files: fix pathspec display on error · 0f64bfa9
      Clemens Buchacher authored
      The following sequence of commands reveals an issue with error
      reporting of relative paths:
       $ mkdir sub
       $ cd sub
       $ git ls-files --error-unmatch ../bbbbb
       error: pathspec 'b' did not match any file(s) known to git.
       $ git commit --error-unmatch ../bbbbb
       error: pathspec 'b' did not match any file(s) known to git.
      This bug is visible only if the normalized path (i.e., the relative
      path from the repository root) is longer than the prefix.
      Otherwise, the code skips over the normalized path and reads from
      an unused memory location which still contains a leftover of the
      original command line argument.
      So instead, use the existing facilities to deal with relative paths
      Also fix inconsistency between "checkout" and "commit", e.g.
          $ cd Documentation
          $ git checkout nosuch.txt
          error: pathspec 'Documentation/nosuch.txt' did not match...
          $ git commit nosuch.txt
          error: pathspec 'nosuch.txt' did not match...
      by propagating the prefix down the codepath that reports the error.
      Signed-off-by: default avatarClemens Buchacher <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  4. 05 Jun, 2010 1 commit
  5. 06 Feb, 2010 1 commit
    • Jeff King's avatar
      Fix invalid read in quote_c_style_counted · 84249819
      Jeff King authored
      This function did not work on strings that were not NUL-terminated. It
      reads through a length-bounded string, searching for characters in need of
      quoting. After we find one, we output the quoted character, then advance
      our pointer to find the next one. However, we never decremented the
      length, meaning we ended up looking at whatever random junk was stored
      after the string.
      This bug was not found by the existing tests because most code paths feed
      a NUL-terminated string. The notable exception is a directory name being
      fed by ls-tree.
      Signed-off-by: default avatarJeff King <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  6. 12 Jan, 2010 1 commit
  7. 21 Jun, 2009 1 commit
    • Linus Torvalds's avatar
      Fix various sparse warnings in the git source code · 2af202be
      Linus Torvalds authored
      There are a few remaining ones, but this fixes the trivial ones. It boils
      down to two main issues that sparse complains about:
       - warning: Using plain integer as NULL pointer
         Sparse doesn't like you using '0' instead of 'NULL'. For various good
         reasons, not the least of which is just the visual confusion. A NULL
         pointer is not an integer, and that whole "0 works as NULL" is a
         historical accident and not very pretty.
         A few of these remain: zlib is a total mess, and Z_NULL is just a 0.
         I didn't touch those.
       - warning: symbol 'xyz' was not declared. Should it be static?
         Sparse wants to see declarations for any functions you export. A lack
         of a declaration tends to mean that you should either add one, or you
         should mark the function 'static' to show that it's in file scope.
         A few of these remain: I only did the ones that should obviously just
         be made static.
      That 'wt_status_submodule_summary' one is debatable. It has a few related
      flags (like 'wt_status_use_color') which _are_ declared, and are used by
      builtin-commit.c. So maybe we'd like to export it at some point, but it's
      not declared now, and not used outside of that file, so 'static' it is in
      this patch.
      Signed-off-by: default avatarLinus Torvalds <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  8. 30 Mar, 2009 2 commits
  9. 28 Jun, 2008 1 commit
    • Dmitry Potapov's avatar
      shrink git-shell by avoiding redundant dependencies · 5b8e6f85
      Dmitry Potapov authored
      A lot of modules that have nothing to do with git-shell functionality
      were linked in, bloating git-shell more than 8 times.
      This patch cuts off redundant dependencies by:
      1. providing stubs for three functions that make no sense for git-shell;
      2. moving quote_path_fully from environment.c to quote.c to make the
         later self sufficient;
      3. moving make_absolute_path into a new separate file.
      The following numbers have been received with the default optimization
      settings on master using GCC 4.1.2:
         text    data     bss     dec     hex filename
       143915    1348   93168  238431   3a35f git-shell
         text    data     bss     dec     hex filename
        17670     788    8232   26690    6842 git-shell
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  10. 08 Mar, 2008 1 commit
  11. 07 Mar, 2008 1 commit
    • Pierre Habouzit's avatar
      unquote_c_style: fix off-by-one. · c8744d6a
      Pierre Habouzit authored
      The optional endp parameter to unquote_c_style() was supposed to point at
      a location past the closing double quote, but it was going one beyond it.
      git-fast-import used this function heavily and the bug caused it to
      misparse the input stream, especially when parsing a rename command:
      	R "filename that needs quoting" rename-target-name
      Because the function erroneously ate the whitespace after the closing dq,
      this triggered "Missing space after source" error when it shouldn't.
      Thanks to Adeodato Simò for having caught this.
      Signed-off-by: default avatarPierre Habouzit <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  12. 27 Dec, 2007 1 commit
  13. 04 Dec, 2007 1 commit
  14. 08 Nov, 2007 1 commit
  15. 04 Nov, 2007 1 commit
  16. 29 Sep, 2007 1 commit
    • Pierre Habouzit's avatar
      strbuf change: be sure ->buf is never ever NULL. · b315c5c0
      Pierre Habouzit authored
      For that purpose, the ->buf is always initialized with a char * buf living
      in the strbuf module. It is made a char * so that we can sloppily accept
      things that perform: sb->buf[0] = '\0', and because you can't pass "" as an
      initializer for ->buf without making gcc unhappy for very good reasons.
      strbuf_init/_detach/_grow have been fixed to trust ->alloc and not ->buf
      as a consequence strbuf_detach is _mandatory_ to detach a buffer, copying
      ->buf isn't an option anymore, if ->buf is going to escape from the scope,
      and eventually be free'd.
      API changes:
        * strbuf_setlen now always works, so just make strbuf_reset a convenience
        * strbuf_detatch takes a size_t* optional argument (meaning it can be
          NULL) to copy the buffer's len, as it was needed for this refactor to
          make the code more readable, and working like the callers.
      Signed-off-by: default avatarPierre Habouzit <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  17. 21 Sep, 2007 3 commits
    • Pierre Habouzit's avatar
      sq_quote_argv and add_to_string rework with strbuf's. · 7a33bcbe
      Pierre Habouzit authored
      * sq_quote_buf is made public, and works on a strbuf.
      * sq_quote_argv also works on a strbuf.
      * make sq_quote_argv take a "maxlen" argument to check the buffer won't grow
        too big.
      Signed-off-by: default avatarPierre Habouzit <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
    • Pierre Habouzit's avatar
      Full rework of quote_c_style and write_name_quoted. · 663af342
      Pierre Habouzit authored
      * quote_c_style works on a strbuf instead of a wild buffer.
      * quote_c_style is now clever enough to not add double quotes if not needed.
      * write_name_quoted inherits those advantages, but also take a different
        set of arguments. Now instead of asking for quotes or not, you pass a
        "terminator". If it's \0 then we assume you don't want to escape, else C
        escaping is performed. In any case, the terminator is also appended to the
        stream. It also no longer takes the prefix/prefix_len arguments, as it's
        seldomly used, and makes some optimizations harder.
      * write_name_quotedpfx is created to work like write_name_quoted and take
        the prefix/prefix_len arguments.
      Thanks to those API changes, diff.c has somehow lost weight, thanks to the
      removal of functions that were wrappers around the old write_name_quoted
      trying to give it a semantics like the new one, but performing a lot of
      allocations for this goal. Now we always write directly to the stream, no
      intermediate allocation is performed.
      As a side effect of the refactor in builtin-apply.c, the length of the bar
      graphs in diffstats are not affected anymore by the fact that the path was
      Signed-off-by: default avatarPierre Habouzit <[email protected]>
    • Pierre Habouzit's avatar
      Rework unquote_c_style to work on a strbuf. · 7fb1011e
      Pierre Habouzit authored
      If the gain is not obvious in the diffstat, the resulting code is more
      readable, _and_ in checkout-index/update-index we now reuse the same buffer
      to unquote strings instead of always freeing/mallocing.
      This also is more coherent with the next patch that reworks quoting
      The quoting function is also made more efficient scanning for backslashes
      and treating portions of strings without a backslash at once.
      Signed-off-by: default avatarPierre Habouzit <[email protected]>
  18. 24 Jun, 2007 1 commit
    • Junio C Hamano's avatar
      Add core.quotepath configuration variable. · 9378c161
      Junio C Hamano authored
      We always quote "unusual" byte values in a pathname using
      C-string style, to make it safer for parsing scripts that do not
      handle NUL separated records well (or just too lazy to bother).
      The absolute minimum bytes that need to be quoted for this
      purpose are TAB, LF (and other control characters), double quote
      and backslash.
      However, we have also always quoted the bytes in high 8-bit
      range; this was partly because we were lazy and partly because
      we were being cautious.
      This introduces an internal "quote_path_fully" variable, and
      core.quotepath configuration variable to control it.  When set
      to false, it does not quote bytes in high 8-bit range anymore
      but passes them intact.
      The variable defaults to "true" to retain the traditional
      behaviour for now.
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  19. 08 Jun, 2007 1 commit
  20. 28 Jan, 2007 1 commit
  21. 31 Oct, 2006 1 commit
  22. 16 Sep, 2006 1 commit
  23. 11 Sep, 2006 1 commit
  24. 02 Sep, 2006 1 commit
    • Christian Couder's avatar
      Trace into a file or an open fd and refactor tracing code. · 6ce4e61f
      Christian Couder authored
      If GIT_TRACE is set to an absolute path (starting with a
      '/' character), we interpret this as a file path and we
      trace into it.
      Also if GIT_TRACE is set to an integer value greater than
      1 and lower than 10, we interpret this as an open fd value
      and we trace into it.
      Note that this behavior is not compatible with the
      previous one.
      We also trace whole messages using one write(2) call to
      make sure messages from processes do net get mixed up in
      the middle.
      This patch makes it possible to get trace information when
      running "make test".
      Signed-off-by: Christian Couder's avatarChristian Couder <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  25. 31 Aug, 2006 1 commit
  26. 09 Jul, 2006 1 commit
  27. 28 Jun, 2006 1 commit
  28. 19 Jun, 2006 1 commit
  29. 17 Apr, 2006 1 commit
  30. 21 Dec, 2005 1 commit
  31. 29 Nov, 2005 1 commit
  32. 24 Oct, 2005 1 commit
    • Linus Torvalds's avatar
      Add git-shell. · 35eb2d36
      Linus Torvalds authored
      This adds a very git specific restricted shell, that can be
      added to /etc/shells and set to the pw_shell in the /etc/passwd
      file, to give users ability to push into repositories over ssh
      without giving them full interactive shell acount.
      [jc: I updated Linus' patch to match what the current sq_quote()
      Signed-off-by: default avatarLinus Torvalds <[email protected]>
      Signed-off-by: default avatarJunio C Hamano <[email protected]>
  33. 18 Oct, 2005 2 commits
  34. 17 Oct, 2005 1 commit
    • Junio C Hamano's avatar
      Do not quote SP. · 25785195
      Junio C Hamano authored
      Follow the "encode minimally" principle -- our tools, including
      git-apply and git-status, can handle pathnames with embedded SP just
      fine.  The only problematic ones are TAB and LF, and we need to quote
      the metacharacters introduced for quoting.
      Signed-off-by: default avatarJunio C Hamano <[email protected]>