summaryrefslogtreecommitdiff
path: root/strbuf.c
AgeCommit message (Collapse)AuthorFilesLines
2013-01-05Merge branch 'mh/unify-xml-in-imap-send-and-http-push'Libravatar Junio C Hamano1-0/+26
Update imap-send to reuse xml quoting code from http-push codepath, clean up some code, and fix a small bug. * mh/unify-xml-in-imap-send-and-http-push: wrap_in_html(): process message in bulk rather than line-by-line wrap_in_html(): use strbuf_addstr_xml_quoted() imap-send: change msg_data from storing (ptr, len) to storing strbuf imap-send: correctly report errors reading from stdin imap-send: store all_msgs as a strbuf lf_to_crlf(): NUL-terminate msg_data::data xml_entities(): use function strbuf_addstr_xml_quoted() Add new function strbuf_add_xml_quoted()
2012-11-26Add new function strbuf_add_xml_quoted()Libravatar Michael Haggerty1-0/+26
Substantially the same code is present in http-push.c and imap-send.c, so make a library function out of it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-04strbuf_split*(): rename "delim" parameter to "terminator"Libravatar Michael Haggerty1-2/+3
The word "delimiter" suggests that the argument separates the substrings, whereas in fact (1) the delimiter characters are included in the output, and (2) if the input string ends with the delimiter, then the output does not include a final empty string. So rename the "delim" arguments of the strbuf_split() family of functions to "terminator", which is more suggestive of how it is used. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
2012-11-04strbuf_split_buf(): simplify iterationLibravatar Michael Haggerty1-13/+10
While iterating, update str and slen to keep track of the part of the string that hasn't been processed yet rather than computing things relative to the start of the original string. This eliminates one local variable, reduces the scope of another, and reduces the amount of arithmetic needed within the loop. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
2012-11-04strbuf_split_buf(): use ALLOC_GROW()Libravatar Michael Haggerty1-10/+7
Use ALLOC_GROW() rather than inline code to manage memory in strbuf_split_buf(). Rename "pos" to "nr" because it better describes the use of the variable and it better conforms to the "ALLOC_GROW" idiom. Also, instead of adding a sentinal NULL value after each entry is added to the list, only add it once after all of the entries have been added. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
2012-10-25Merge branch 'jk/strbuf-detach-always-non-null'Libravatar Jeff King1-1/+3
* jk/strbuf-detach-always-non-null: strbuf: always return a non-NULL value from strbuf_detach
2012-10-18strbuf: always return a non-NULL value from strbuf_detachLibravatar Jeff King1-1/+3
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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-15strbuf.c: mark a private file-scope symbol as staticLibravatar Junio C Hamano1-11/+2
Also remove an unused function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-24strbuf: convenience format functions with \n automatically appendedLibravatar Nguyễn Thái Ngọc Duy1-0/+33
These functions are helpful when we do not want to expose \n to translators. For example printf("hello world\n"); can be converted to printf_ln(_("hello world")); Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-26Merge branch 'tr/maint-bundle-long-subject'Libravatar Junio C Hamano1-0/+16
* tr/maint-bundle-long-subject: t5704: match tests to modern style strbuf: improve strbuf_get*line documentation bundle: use a strbuf to scan the log for boundary commits bundle: put strbuf_readline_fd in strbuf.c with adjustments
2012-02-22bundle: put strbuf_readline_fd in strbuf.c with adjustmentsLibravatar Thomas Rast1-0/+16
The comment even said that it should eventually go there. While at it, match the calling convention and name of the function to the strbuf_get*line family. So it now is strbuf_getwholeline_fd. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-19Merge branch 'jk/credentials'Libravatar Junio C Hamano1-0/+37
* jk/credentials: t: add test harness for external credential helpers credentials: add "store" helper strbuf: add strbuf_add*_urlencode Makefile: unix sockets may not available on some platforms credentials: add "cache" helper docs: end-user documentation for the credential subsystem credential: make relevance of http path configurable credential: add credential.*.username credential: apply helper config http: use credential API to get passwords credential: add function for parsing url components introduce credentials API t5550: fix typo test-lib: add test_config_global variant Conflicts: strbuf.c
2011-12-12strbuf: add strbuf_add*_urlencodeLibravatar Jeff King1-0/+37
This just follows the rfc3986 rules for percent-encoding url data into a strbuf. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-11-08fmt-merge-msg: Add contents of merged tag in the merge messageLibravatar Junio C Hamano1-0/+14
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: Junio C Hamano <gitster@pobox.com>
2011-10-18strbuf.c: remove unnecessary strbuf_grow() from strbuf_getwholeline()Libravatar Brandon Casey1-1/+0
This use of strbuf_grow() is a historical artifact that was once used to ensure that strbuf.buf was allocated and properly nul-terminated. This was added before the introduction of the slopbuf in b315c5c0, which guarantees that strbuf.buf always points to a usable nul-terminated string. So let's remove it. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-02Merge branch 'tr/maint-strbuf-grow-nul-termination'Libravatar Junio C Hamano1-4/+5
* tr/maint-strbuf-grow-nul-termination: strbuf_grow(): maintain nul-termination even for new buffer
2011-08-29strbuf_grow(): maintain nul-termination even for new bufferLibravatar Thomas Rast1-4/+5
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: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-07-19Merge branch 'jk/maint-config-param'Libravatar Junio C Hamano1-6/+9
* jk/maint-config-param: config: use strbuf_split_str instead of a temporary strbuf strbuf: allow strbuf_split to work on non-strbufs config: avoid segfault when parsing command-line config config: die on error in command-line config fix "git -c" parsing of values with equals signs strbuf_split: add a max parameter
2011-06-22strbuf: allow strbuf_split to work on non-strbufsLibravatar Jeff King1-6/+6
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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-22strbuf_split: add a max parameterLibravatar Jeff King1-2/+5
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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-27Merge branch 'ef/maint-strbuf-init'Libravatar Junio C Hamano1-1/+3
* ef/maint-strbuf-init: config: support values longer than 1023 bytes strbuf: make sure buffer is zero-terminated
2011-04-11strbuf: make sure buffer is zero-terminatedLibravatar Erik Faye-Lund1-1/+3
strbuf_init does not zero-terminate the initial buffer when hint is non-zero. Fix this so we can rely on the string to be zero-terminated even if we haven't filled it with anything yet. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-02-26strbuf: add strbuf_vaddfLibravatar Jeff King1-10/+15
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>
2011-02-10compat: helper for detecting unsigned overflowLibravatar Jonathan Nieder1-2/+3
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>
2010-11-10strbuf: move strbuf_branchname to sha1_name.cLibravatar Jonathan Nieder1-18/+0
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>
2010-09-15disallow branch names that start with a hyphenLibravatar Junio C Hamano1-0/+2
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>
2010-01-20Merge branch 'ap/merge-backend-opts'Libravatar Junio C Hamano1-0/+9
* 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
2010-01-20Merge branch 'jk/warn-author-committer-after-commit'Libravatar Junio C Hamano1-0/+17
* 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
2010-01-17git merge -X<option>Libravatar Avery Pennarun1-0/+9
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>
2010-01-14strbuf: add strbuf_addbuf_percentquoteLibravatar Jeff King1-0/+11
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>
2010-01-14strbuf_expand: convert "%%" to "%"Libravatar Jeff King1-0/+6
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>
2010-01-12strbuf.c: remove unused functionLibravatar Junio C Hamano1-7/+0
strbuf_tolower() is not used anywhere. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-08-05strbuf: add new function strbuf_getwholeline()Libravatar Brandon Casey1-3/+12
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>
2009-06-23fread does not return negative on errorLibravatar Roel Kluin1-1/+1
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>
2009-03-22strbuf_check_branch_ref(): a helper to check a refname for a branchLibravatar Junio C Hamano1-0/+8
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>
2009-03-22strbuf_branchname(): a wrapper for branch name shorthandsLibravatar Junio C Hamano1-0/+9
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>
2009-03-20Microoptimize strbuf_cmpLibravatar Alex Riesen1-8/+5
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>
2009-01-06strbuf: instate cleanup rule in case of non-memory errorsLibravatar René Scharfe1-4/+13
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>
2008-12-17Add generic 'strbuf_readlink()' helper functionLibravatar Linus Torvalds1-0/+27
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>
2008-11-23add strbuf_expand_dict_cb(), a helper for simple casesLibravatar René Scharfe1-0/+16
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>
2008-07-13Add some useful functions for strbuf manipulation.Libravatar Lukas Sandström1-0/+70
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-13Make some strbuf_*() struct strbuf arguments const.Libravatar Lukas Sandström1-1/+1
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-09Avoid a useless prefix lookup in strbuf_expand()Libravatar Marco Costalba1-11/+8
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>
2008-01-03Uninline prefixcmp()Libravatar Junio C Hamano1-0/+9
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>
2007-11-14Merge branch 'rs/pretty'Libravatar Junio C Hamano1-0/+31
* 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()
2007-11-14Handle broken vsnprintf implementations in strbufLibravatar Shawn O. Pearce1-3/+4
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>
2007-11-11add strbuf_adddup()Libravatar René Scharfe1-0/+7
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>
2007-11-09--pretty=format: on-demand format expansionLibravatar René Scharfe1-0/+24
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>
2007-09-29strbuf_read_file enhancement, and use it.Libravatar Pierre Habouzit1-2/+2
* 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>
2007-09-29strbuf change: be sure ->buf is never ever NULL.Libravatar Pierre Habouzit1-11/+19
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>