Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Feb 26, 2011
  1. @peff

    strbuf: add strbuf_vaddf

    peff authored committed
    In a variable-args function, the code for writing into a strbuf is
    non-trivial. We ended up cutting and pasting it in several places
    because there was no vprintf-style function for strbufs (which in turn
    was held up by a lack of va_copy).
    
    Now that we have a fallback va_copy, we can add strbuf_vaddf, the
    strbuf equivalent of vsprintf. And we can clean up the cut and paste
    mess.
    
    Signed-off-by: Jeff King <peff@peff.net>
    Improved-by: Christian Couder <christian.couder@gmail.com>
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Feb 10, 2011
  1. @jrn

    compat: helper for detecting unsigned overflow

    jrn authored committed
    The idiom (a + b < a) works fine for detecting that an unsigned
    integer has overflowed, but a more explicit
    
    	unsigned_add_overflows(a, b)
    
    might be easier to read.
    
    Define such a macro, expanding roughly to ((a) < UINT_MAX - (b)).
    Because the expansion uses each argument only once outside of sizeof()
    expressions, it is safe to use with arguments that have side effects.
    
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 10, 2010
  1. @jrn

    strbuf: move strbuf_branchname to sha1_name.c

    jrn authored committed
    strbuf_branchname is a thin wrapper around interpret_branch_name
    from sha1_name.o.  Most strbuf.o users do not need it.
    
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 15, 2010
  1. disallow branch names that start with a hyphen

    authored
    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: Junio C Hamano <gitster@pobox.com>
Commits on Jan 21, 2010
  1. Merge branch 'ap/merge-backend-opts'

    authored
    * ap/merge-backend-opts:
      Document that merge strategies can now take their own options
      Extend merge-subtree tests to test -Xsubtree=dir.
      Make "subtree" part more orthogonal to the rest of merge-recursive.
      pull: Fix parsing of -X<option>
      Teach git-pull to pass -X<option> to git-merge
      git merge -X<option>
      git-merge-file --ours, --theirs
    
    Conflicts:
    	git-compat-util.h
Commits on Jan 20, 2010
  1. Merge branch 'jk/warn-author-committer-after-commit'

    authored
    * jk/warn-author-committer-after-commit:
      user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere
      commit.c::print_summary: do not release the format string too early
      commit: allow suppression of implicit identity advice
      commit: show interesting ident information in summary
      strbuf: add strbuf_addbuf_percentquote
      strbuf_expand: convert "%%" to "%"
    
    Conflicts:
    	builtin-commit.c
    	ident.c
Commits on Jan 18, 2010
  1. @apenwarr

    git merge -X<option>

    apenwarr authored committed
    Teach "-X <option>" command line argument to "git merge" that is passed to
    strategy implementations.  "ours" and "theirs" autoresolution introduced
    by the previous commit can be asked to the recursive strategy.
    
    Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 14, 2010
  1. @peff

    strbuf: add strbuf_addbuf_percentquote

    peff authored committed
    This is handy for creating strings which will be fed to printf() or
    strbuf_expand().
    
    Signed-off-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @peff

    strbuf_expand: convert "%%" to "%"

    peff authored committed
    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: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 12, 2010
  1. strbuf.c: remove unused function

    authored
    strbuf_tolower() is not used anywhere.
    
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Aug 5, 2009
  1. @drafnel

    strbuf: add new function strbuf_getwholeline()

    drafnel authored committed
    This function is just like strbuf_getline() except it retains the
    line-termination character.  This function will be used by the mailinfo
    and mailsplit builtins which require the entire line for parsing.
    
    Signed-off-by: Brandon Casey <drafnel@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jun 23, 2009
  1. @RoelKluin

    fread does not return negative on error

    RoelKluin authored committed
    size_t res cannot be less than 0. fread returns 0 on error.
    
    Reported-by: Ingo Molnar <mingo@elte.hu>
    Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 23, 2009
  1. strbuf_check_branch_ref(): a helper to check a refname for a branch

    authored
    This allows a common calling sequence
    
    	strbuf_branchname(&ref, name);
    	strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
    	if (check_ref_format(ref.buf))
    		die(...);
    
    to be refactored into
    
    	if (strbuf_check_branch_ref(&ref, name))
    		die(...);
    
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. strbuf_branchname(): a wrapper for branch name shorthands

    authored
    The function takes a user-supplied string that is supposed to be a branch
    name, and puts it in a strbuf after expanding possible shorthand notation.
    
    A handful of open coded sequence to do this in the existing code have been
    changed to use this helper function.
    
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Mar 20, 2009
  1. @raalkml

    Microoptimize strbuf_cmp

    raalkml authored committed
    It can be less object code and may be even faster, even if at the
    moment there is no callers to take an advantage of that. This
    implementation can be trivially made inlinable later.
    
    Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 7, 2009
  1. strbuf: instate cleanup rule in case of non-memory errors

    René Scharfe authored committed
    Make all strbuf functions that can fail free() their memory on error if
    they have allocated it.  They don't shrink buffers that have been grown,
    though.
    
    This allows for easier error handling, as callers only need to call
    strbuf_release() if A) the command succeeded or B) if they would have had
    to do so anyway because they added something to the strbuf themselves.
    
    Bonus hunk: document strbuf_readlink.
    
    Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Dec 17, 2008
  1. @torvalds

    Add generic 'strbuf_readlink()' helper function

    torvalds authored committed
    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: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 24, 2008
  1. add strbuf_expand_dict_cb(), a helper for simple cases

    René Scharfe authored committed
    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: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jul 13, 2008
  1. Add some useful functions for strbuf manipulation.

    Lukas Sandström authored committed
    Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. Make some strbuf_*() struct strbuf arguments const.

    Lukas Sandström authored committed
    Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Feb 10, 2008
  1. @mcostalba

    Avoid a useless prefix lookup in strbuf_expand()

    mcostalba authored committed
    Currently, the --pretty=format prefix is looked up in a
    tight loop in strbuf_expand(), if prefix is found it is then
    used as argument for format_commit_item() that does another
    search by a switch statement to select the proper operation.
    
    Because the switch statement is already able to discard
    unknown matches we don't need the prefix lookup before
    to call format_commit_item().
    
    Signed-off-by: Marco Costalba <mcostalba@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jan 3, 2008
  1. Uninline prefixcmp()

    authored
    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: Junio C Hamano <gitster@pobox.com>
Commits on Nov 14, 2007
  1. Merge branch 'rs/pretty'

    authored
    * rs/pretty:
      Fix preprocessor logic that determines the availablity of strchrnul().
      Simplify strchrnul() compat code
      --format=pretty: avoid calculating expensive expansions twice
      add strbuf_adddup()
      --pretty=format: parse commit message only once
      --pretty=format: on-demand format expansion
      Add strchrnul()
  2. @spearce

    Handle broken vsnprintf implementations in strbuf

    spearce authored committed
    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: Shawn O. Pearce <spearce@spearce.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 11, 2007
  1. add strbuf_adddup()

    René Scharfe authored committed
    Add a new function, strbuf_adddup(), that appends a duplicate of a
    part of a struct strbuf to end of the latter.
    
    Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 9, 2007
  1. --pretty=format: on-demand format expansion

    René Scharfe authored committed
    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: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 30, 2007
  1. @MadCoder

    strbuf_read_file enhancement, and use it.

    MadCoder authored committed
    * make strbuf_read_file take a size hint (works like strbuf_read)
    * use it in a couple of places.
    
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 29, 2007
  1. @MadCoder

    strbuf change: be sure ->buf is never ever NULL.

    MadCoder authored committed
    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
    anymore.
    
    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
        macro.
      * 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: Pierre Habouzit <madcoder@debian.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 27, 2007
  1. Add strbuf_read_file().

    Kristian Høgsberg authored committed
    Signed-off-by: Kristian Høgsberg <krh@redhat.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 26, 2007
  1. @MadCoder

    Add strbuf_cmp.

    MadCoder authored committed
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 21, 2007
  1. @MadCoder

    strbuf API additions and enhancements.

    MadCoder authored committed
    Add strbuf_remove, change strbuf_insert:
      As both are special cases of strbuf_splice, implement them as such.
      gcc is able to do the math and generate almost optimal code this way.
    
    Add strbuf_swap:
      Exchange the values of its arguments.
      Use it in fast-import.c
    
    Also fix spacing issues in strbuf.h
    
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Commits on Sep 18, 2007
  1. @MadCoder

    Drop strbuf's 'eof' marker, and make read_line a first class citizen.

    MadCoder authored committed
    read_line is now strbuf_getline, and is a first class citizen, it returns 0
    when reading a line worked, EOF else.
    
    The ->eof marker was used non-locally by fast-import.c, mimic the same
    behaviour using a static int in "read_next_command", that now returns -1 on
    EOF, and avoids to call strbuf_getline when it's in EOF state.
    
    Also no longer automagically strbuf_release the buffer, it's counter
    intuitive and breaks fast-import in a very subtle way.
    
    Note: being at EOF implies that command_buf.len == 0.
    
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 17, 2007
  1. @MadCoder

    Now that cache.h needs strbuf.h, remove useless includes.

    MadCoder authored committed
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
    Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @MadCoder

    New strbuf APIs: splice and attach.

    MadCoder authored committed
    * strbuf_splice replace a portion of the buffer with another.
    * strbuf_attach replace a strbuf buffer with the given one, that should be
      malloc'ed. Then it enforces strbuf's invariants. If alloc > len, then this
      function has negligible cost, else it will perform a realloc, possibly
      with a cost.
    
    Also some style issues are fixed now.
    
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
    Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Sep 10, 2007
  1. @MadCoder

    Strbuf API extensions and fixes.

    MadCoder authored committed
      * Add strbuf_rtrim to remove trailing spaces.
      * Add strbuf_insert to insert data at a given position.
      * Off-by one fix in strbuf_addf: strbuf_avail() does not counts the final
        \0 so the overflow test for snprintf is the strict comparison. This is
        not critical as the growth mechanism chosen will always allocate _more_
        memory than asked, so the second test will not fail. It's some kind of
        miracle though.
      * Add size extension hints for strbuf_init and strbuf_read. If 0, default
        applies, else:
          + initial buffer has the given size for strbuf_init.
          + first growth checks it has at least this size rather than the
            default 8192.
    
    Signed-off-by: Pierre Habouzit <madcoder@debian.org>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Something went wrong with that request. Please try again.