1. 11 4月, 2013 1 次提交
    • A
      strbuf: create strbuf_humanise_bytes() to show byte sizes · 079b546a
      Antoine Pelisse 提交于
      Humanization of downloaded size is done in the same function as text
      formatting in 'process.c'. The code cannot be reused easily elsewhere.
      
      Separate text formatting from size simplification and make the
      function public in strbuf so that it can easily be used by other
      callers.
      
      We now can use strbuf_humanise_bytes() for both downloaded size and
      download speed calculation. One of the drawbacks is that speed will
      now look like this when download is stalled: "0 bytes/s" instead of
      "0 KiB/s".
      Signed-off-by: NAntoine Pelisse <apelisse@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      079b546a
  2. 17 1月, 2013 1 次提交
    • J
      Allow custom "comment char" · eff80a9f
      Junio C Hamano 提交于
      Some users do want to write a line that begin with a pound sign, #,
      in their commit log message.  Many tracking system recognise
      a token of #<bugid> form, for example.
      
      The support we offer these use cases is not very friendly to the end
      users.  They have a choice between
      
       - Don't do it.  Avoid such a line by rewrapping or indenting; and
      
       - Use --cleanup=whitespace but remove all the hint lines we add.
      
      Give them a way to set a custom comment char, e.g.
      
          $ git -c core.commentchar="%" commit
      
      so that they do not have to do either of the two workarounds.
      
      [jc: although I started the topic, all the tests and documentation
      updates, many of the call sites of the new strbuf_add_commented_*()
      functions, and the change to git-submodule.sh scripted Porcelain are
      from Ralf.]
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NRalf Thielow <ralf.thielow@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eff80a9f
  3. 27 11月, 2012 1 次提交
  4. 04 11月, 2012 3 次提交
  5. 19 10月, 2012 1 次提交
    • J
      strbuf: always return a non-NULL value from strbuf_detach · 08ad56f3
      Jeff King 提交于
      The current behavior is to return NULL when strbuf did not
      actually allocate a string. This can be quite surprising to
      callers, though, who may feed the strbuf from arbitrary data
      and expect to always get a valid value.
      
      In most cases, it does not make a difference because calling
      any strbuf function will cause an allocation (even if the
      function ends up not inserting any data). But if the code is
      structured like:
      
        struct strbuf buf = STRBUF_INIT;
        if (some_condition)
      	  strbuf_addstr(&buf, some_string);
        return strbuf_detach(&buf, NULL);
      
      then you may or may not return NULL, depending on the
      condition. This can cause us to segfault in http-push
      (when fed an empty URL) and in http-backend (when an empty
      parameter like "foo=bar&&" is in the $QUERY_STRING).
      
      This patch forces strbuf_detach to allocate an empty
      NUL-terminated string when it is called on a strbuf that has
      not been allocated.
      
      I investigated all call-sites of strbuf_detach. The majority
      are either not affected by the change (because they call a
      strbuf_* function unconditionally), or can handle the empty
      string just as easily as NULL.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      08ad56f3
  6. 16 9月, 2012 1 次提交
  7. 25 4月, 2012 1 次提交
  8. 23 2月, 2012 1 次提交
  9. 13 12月, 2011 1 次提交
  10. 09 11月, 2011 1 次提交
    • J
      fmt-merge-msg: Add contents of merged tag in the merge message · 895680f0
      Junio C Hamano 提交于
      When a contributor asks the integrator to merge her history, a signed tag
      can be a good vehicle to communicate the authenticity of the request while
      conveying other information such as the purpose of the topic.
      
      E.g. a signed tag "for-linus" can be created, and the integrator can run:
      
         $ git pull git://example.com/work.git/ for-linus
      
      This would allow the integrator to run "git verify-tag FETCH_HEAD" to
      validate the signed tag.
      
      Update fmt-merge-msg so that it pre-fills the merge message template with
      the body (but not signature) of the tag object to help the integrator write
      a better merge message, in the same spirit as the existing merge.log summary
      lines.
      
      The message that comes from GPG signature validation is also included in
      the merge message template to help the integrator verify it, but they are
      prefixed with "#" to make them comments.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      895680f0
  11. 19 10月, 2011 1 次提交
  12. 30 8月, 2011 1 次提交
    • T
      strbuf_grow(): maintain nul-termination even for new buffer · 8c74ef1e
      Thomas Rast 提交于
      In the case where sb is initialized to the slopbuf (through
      strbuf_init(sb,0) or STRBUF_INIT), strbuf_grow() loses the terminating
      nul: it grows the buffer, but gives ALLOC_GROW a NULL source to avoid
      it being freed.  So ALLOC_GROW does not copy anything to the new
      memory area.
      
      This subtly broke the call to strbuf_getline in read_next_command()
      [fast-import.c:1855], which goes
      
          strbuf_detach(&command_buf, NULL);  # command_buf is now = STRBUF_INIT
          stdin_eof = strbuf_getline(&command_buf, stdin, '\n');
          if (stdin_eof)
                  return EOF;
      
      In strbuf_getwholeline, this did
      
          strbuf_grow(sb, 0);  # loses nul-termination
          if (feof(fp))
                  return EOF;
          strbuf_reset(sb);    # this would have nul-terminated!
      
      Valgrind found this because fast-import subsequently uses prefixcmp()
      on command_buf.buf, which after the EOF exit contains only
      uninitialized memory.
      
      Arguably strbuf_getwholeline is also broken, in that it touches the
      buffer before deciding whether to do any work.  However, it seems more
      futureproof to not let the strbuf API lose the nul-termination by its
      own fault.
      
      So make sure that strbuf_grow() puts in a nul even if it has nowhere
      to copy it from.  This makes strbuf_grow(sb, 0) a semantic no-op as
      far as readers of the buffer are concerned.
      
      Also remove the nul-termination added by strbuf_init, which is made
      redudant.
      Signed-off-by: NThomas Rast <trast@student.ethz.ch>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8c74ef1e
  13. 23 6月, 2011 2 次提交
    • J
      strbuf: allow strbuf_split to work on non-strbufs · 2f1d9e2b
      Jeff King 提交于
      The strbuf_split function takes a strbuf as input, and
      outputs a list of strbufs. However, there is no reason that
      the input has to be a strbuf, and not an arbitrary buffer.
      
      This patch adds strbuf_split_buf for a length-delimited
      buffer, and strbuf_split_str for NUL-terminated strings.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f1d9e2b
    • J
      strbuf_split: add a max parameter · 28fc3a68
      Jeff King 提交于
      Sometimes when splitting, you only want a limited number of
      fields, and for the final field to contain "everything
      else", even if it includes the delimiter.
      
      This patch introduces strbuf_split_max, which provides a
      "max number of fields" parameter; it behaves similarly to
      perl's "split" with a 3rd field.
      
      The existing 2-argument form of strbuf_split is retained for
      compatibility and ease-of-use.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      28fc3a68
  14. 12 4月, 2011 1 次提交
  15. 26 2月, 2011 1 次提交
  16. 11 2月, 2011 1 次提交
  17. 11 11月, 2010 1 次提交
  18. 16 9月, 2010 1 次提交
    • J
      disallow branch names that start with a hyphen · 63486240
      Junio C Hamano 提交于
      The current command line parser is overly lax in places and allows a
      branch whose name begins with a hyphen e.g. "-foo" to be created, but the
      parseopt infrastructure in general does not like to parse anything that
      begins with a dash as a short-hand refname.  "git checkout -foo" won't
      work, nor will "git branch -d -foo" (even though "git branch -d -- -foo"
      works, it does so by mistake; we should not be taking anything but
      pathspecs after double-dash).
      
      All the codepaths that create a new branch ref, including the destination
      of "branch -m src dst", use strbuf_check_branch_ref() to validate if the
      given name is suitable as a branch name.  Tighten it to disallow a branch
      that begins with a hyphen.
      
      You can still get rid of historical mistakes with
      
        $ git update-ref -d refs/heads/-foo
      
      and third-party Porcelains are free to keep using update-ref to create
      refs with a path component that begins with "-".
      
      Issue originally raised by Clemens Buchacher.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      63486240
  19. 18 1月, 2010 1 次提交
  20. 15 1月, 2010 2 次提交
    • J
      strbuf: add strbuf_addbuf_percentquote · 361df5df
      Jeff King 提交于
      This is handy for creating strings which will be fed to printf() or
      strbuf_expand().
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      361df5df
    • J
      strbuf_expand: convert "%%" to "%" · 0a0416a3
      Jeff King 提交于
      The only way to safely quote arbitrary text in a pretty-print user
      format is to replace instances of "%" with "%x25". This is slightly
      unreadable, and many users would expect "%%" to produce a single
      "%", as that is what printf format specifiers do.
      
      This patch converts "%%" to "%" for all users of strbuf_expand():
      
       (1) git-daemon interpolated paths
      
       (2) pretty-print user formats
      
       (3) merge driver command lines
      
      Case (1) was already doing the conversion itself outside of
      strbuf_expand(). Case (2) is the intended beneficiary of this patch.
      Case (3) users probably won't notice, but as this is user-facing
      behavior, consistently providing the quoting mechanism makes sense.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0a0416a3
  21. 12 1月, 2010 1 次提交
  22. 06 8月, 2009 1 次提交
  23. 24 6月, 2009 1 次提交
  24. 23 3月, 2009 2 次提交
  25. 21 3月, 2009 1 次提交
  26. 07 1月, 2009 1 次提交
  27. 18 12月, 2008 1 次提交
    • L
      Add generic 'strbuf_readlink()' helper function · b11b7e13
      Linus Torvalds 提交于
      It was already what 'git apply' did in read_old_data(), just export it
      as a real function, and make it be more generic.
      
      In particular, this handles the case of the lstat() st_size data not
      matching the readlink() return value properly (which apparently happens
      at least on NTFS under Linux).  But as a result of this you could also
      use the new function without even knowing how big the link is going to
      be, and it will allocate an appropriately sized buffer.
      
      So we pass in the st_size of the link as just a hint, rather than a
      fixed requirement.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b11b7e13
  28. 24 11月, 2008 1 次提交
    • R
      add strbuf_expand_dict_cb(), a helper for simple cases · 9b864e73
      René Scharfe 提交于
      The new callback function strbuf_expand_dict_cb() can be used together
      with strbuf_expand() if there is only a small number of placeholders
      for static replacement texts.  It expects its dictionary as an array of
      placeholder+value pairs as context parameter, terminated by an entry
      with the placeholder member set to NULL.
      
      The new helper is intended to aid converting the remaining calls of
      interpolate().  strbuf_expand() is smaller, more flexible and can be
      used to go faster than interpolate(), so it should replace the latter.
      Signed-off-by: NRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9b864e73
  29. 14 7月, 2008 2 次提交
  30. 10 2月, 2008 1 次提交
  31. 03 1月, 2008 1 次提交
    • J
      Uninline prefixcmp() · 698a68be
      Junio C Hamano 提交于
      Now the routine is an open-coded loop that avoids an extra
      strlen() in the previous implementation, it got a bit too big to
      be inlined.  Uninlining it makes code footprint smaller but the
      result still retains the avoidance of strlen() cost.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      698a68be
  32. 14 11月, 2007 1 次提交
    • S
      Handle broken vsnprintf implementations in strbuf · f141bd80
      Shawn O. Pearce 提交于
      Solaris 9's vsnprintf implementation returns -1 if we pass it a
      buffer of length 0.  The only way to get it to give us the actual
      length necessary for the formatted string is to grow the buffer
      out to have at least 1 byte available in the strbuf and then ask
      it to compute the length.
      
      If the available space is 0 I'm growing it out by 64 to ensure
      we will get an accurate length estimate from all implementations.
      Some callers may need to grow the strbuf again but 64 should be a
      reasonable enough initial growth.
      
      We also no longer silently fail to append to the string when we are
      faced with a broken vsnprintf implementation.  On Solaris 9 this
      silent failure caused me to no longer be able to execute "git clone"
      as we tried to exec the empty string rather than "git-clone".
      Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f141bd80
  33. 11 11月, 2007 1 次提交
  34. 09 11月, 2007 1 次提交
    • R
      --pretty=format: on-demand format expansion · cde75e59
      René Scharfe 提交于
      Some of the --pretty=format placeholders expansions are expensive to
      calculate.  This is made worse by the current code's use of
      interpolate(), which requires _all_ placeholders are to be prepared
      up front.
      
      One way to speed this up is to check which placeholders are present
      in the format string and to prepare only the expansions that are
      needed.  That still leaves the allocation overhead of interpolate().
      
      Another way is to use a callback based approach together with the
      strbuf library to keep allocations to a minimum and avoid string
      copies.  That's what this patch does.  It introduces a new strbuf
      function, strbuf_expand().
      
      The function takes a format string, list of placeholder strings,
      a user supplied function 'fn', and an opaque pointer 'context'
      to tell 'fn' what thingy to operate on.
      
      The function 'fn' is expected to accept a strbuf, a parsed
      placeholder string and the 'context' pointer, and append the
      interpolated value for the 'context' thingy, according to the
      format specified by the placeholder.
      
      Thanks to Pierre Habouzit for his suggestion to use strchrnul() and
      the code surrounding its callsite.  And thanks to Junio for most of
      this commit message. :)
      
      Here my measurements of most of Paul Mackerras' test cases that
      highlighted the performance problem (best of three runs):
      
      (master)
      $ time git log --pretty=oneline >/dev/null
      
      real    0m0.390s
      user    0m0.340s
      sys     0m0.040s
      
      (master)
      $ time git log --pretty=raw >/dev/null
      
      real    0m0.434s
      user    0m0.408s
      sys     0m0.016s
      
      (master)
      $ time git log --pretty="format:%H {%P} %ct" >/dev/null
      
      real    0m1.347s
      user    0m0.080s
      sys     0m1.256s
      
      (interp_find_active -- Dscho)
      $ time ./git log --pretty="format:%H {%P} %ct" >/dev/null
      
      real    0m0.694s
      user    0m0.020s
      sys     0m0.672s
      
      (strbuf_expand -- this patch)
      $ time ./git log --pretty="format:%H {%P} %ct" >/dev/null
      
      real    0m0.395s
      user    0m0.352s
      sys     0m0.028s
      Signed-off-by: NRene Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cde75e59