<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/strbuf.c, branch v2.6.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.6.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.6.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2015-08-25T21:57:06Z</updated>
<entry>
<title>Merge branch 'jh/strbuf-read-use-read-in-full'</title>
<updated>2015-08-25T21:57:06Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-08-25T21:57:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3b281d128180cd583db7c7b852909255ffd8f627'/>
<id>urn:sha1:3b281d128180cd583db7c7b852909255ffd8f627</id>
<content type='text'>
strbuf_read() used to have one extra iteration (and an unnecessary
strbuf_grow() of 8kB), which was eliminated.

* jh/strbuf-read-use-read-in-full:
  strbuf_read(): skip unnecessary strbuf_grow() at eof
</content>
</entry>
<entry>
<title>strbuf_read(): skip unnecessary strbuf_grow() at eof</title>
<updated>2015-08-10T19:51:13Z</updated>
<author>
<name>Jim Hill</name>
<email>gjthill@gmail.com</email>
</author>
<published>2015-05-31T18:16:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac'/>
<id>urn:sha1:3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac</id>
<content type='text'>
The loop in strbuf_read() uses xread() repeatedly while extending
the strbuf until the call returns zero.  If the buffer is
sufficiently large to begin with, this results in xread()
returning the remainder of the file to the end (returning
non-zero), the loop extending the strbuf, and then making another
call to xread() to have it return zero.

By using read_in_full(), we can tell when the read reached the end
of file: when it returns less than was requested, it's eof.  This
way we can avoid an extra iteration that allocates an extra 8kB
that is never used.

Signed-off-by: Jim Hill &lt;gjthill@gmail.com&gt;
Reviewed-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/date-mode-format'</title>
<updated>2015-08-03T18:01:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-08-03T18:01:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d939af12bd96db7ad3e671a0585ad8570aa7e9d3'/>
<id>urn:sha1:d939af12bd96db7ad3e671a0585ad8570aa7e9d3</id>
<content type='text'>
Teach "git log" and friends a new "--date=format:..." option to
format timestamps using system's strftime(3).

* jk/date-mode-format:
  strbuf: make strbuf_addftime more robust
  introduce "format" date-mode
  convert "enum date_mode" into a struct
  show-branch: use DATE_RELATIVE instead of magic number
</content>
</entry>
<entry>
<title>strbuf: make strbuf_addftime more robust</title>
<updated>2015-07-21T05:17:06Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-06-30T13:26:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e4f031e34b08e3217c10942e682920a6939308a0'/>
<id>urn:sha1:e4f031e34b08e3217c10942e682920a6939308a0</id>
<content type='text'>
The return value of strftime is poorly designed; when it
returns 0, the caller cannot tell if the buffer was not
large enough, or if the output was actually 0 bytes. In the
original implementation of strbuf_addftime, we simply punted
and guessed that our 128-byte hint would be large enough.

We can do better, though, if we're willing to treat strftime
like less of a black box. We can munge the incoming format
to make sure that it never produces 0-length output, and
then "fix" the resulting output.  That lets us reliably grow
the buffer based on strftime's return value.

Clever-idea-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'mh/strbuf-read-file-returns-ssize-t'</title>
<updated>2015-07-13T21:00:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2015-07-13T21:00:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d790ba92cc534127fc4c0d58a901d1553835aa62'/>
<id>urn:sha1:d790ba92cc534127fc4c0d58a901d1553835aa62</id>
<content type='text'>
Avoid possible ssize_t to int truncation.

* mh/strbuf-read-file-returns-ssize-t:
  strbuf: strbuf_read_file() should return ssize_t
</content>
</entry>
<entry>
<title>strbuf: strbuf_read_file() should return ssize_t</title>
<updated>2015-07-04T01:25:02Z</updated>
<author>
<name>Michael Haggerty</name>
<email>mhagger@alum.mit.edu</email>
</author>
<published>2015-07-03T13:59:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6c8afe495b2cb6e2069942d7c006f6660e186690'/>
<id>urn:sha1:6c8afe495b2cb6e2069942d7c006f6660e186690</id>
<content type='text'>
It is currently declared to return int, which could overflow for
large files.

Signed-off-by: Michael Haggerty &lt;mhagger@alum.mit.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>introduce "format" date-mode</title>
<updated>2015-06-29T18:39:10Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-06-25T16:55:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=aa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d'/>
<id>urn:sha1:aa1462cc3d3b0c4c8ad6a60aaf31e0f3a424162d</id>
<content type='text'>
This feeds the format directly to strftime. Besides being a
little more flexible, the main advantage is that your system
strftime may know more about your locale's preferred format
(e.g., how to spell the days of the week).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: use getdelim if it is available</title>
<updated>2015-04-16T15:15:05Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T09:01:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0cc30e0e842a25846e76e09f62a1d425a25ee556'/>
<id>urn:sha1:0cc30e0e842a25846e76e09f62a1d425a25ee556</id>
<content type='text'>
We spend a lot of time in strbuf_getwholeline in a tight
loop reading characters from a stdio handle into a buffer.
The libc getdelim() function can do this for us with less
overhead. It's in POSIX.1-2008, and was a GNU extension
before that. Therefore we can't rely on it, but can fall
back to the existing getc loop when it is not available.

The HAVE_GETDELIM knob is turned on automatically for Linux,
where we have glibc. We don't need to set any new
feature-test macros, because we already define _GNU_SOURCE.
Other systems that implement getdelim may need to other
macros (probably _POSIX_C_SOURCE &gt;= 200809L), but we can
address that along with setting the Makefile knob after
testing the feature on those systems.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from
(best-of-5):

  real    0m8.601s
  user    0m8.084s
  sys     0m0.524s

to:

  real    0m6.768s
  user    0m6.340s
  sys     0m0.432s

for a wall-clock speedup of 21%.

Based on a patch from Rasmus Villemoes &lt;rv@rasmusvillemoes.dk&gt;.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: avoid calling strbuf_grow</title>
<updated>2015-04-16T15:15:05Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T08:58:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f80c153bea4e0ea86f5b6d32e77df0b69501ee18'/>
<id>urn:sha1:f80c153bea4e0ea86f5b6d32e77df0b69501ee18</id>
<content type='text'>
As with the recent speedup to strbuf_addch, we can avoid
calling strbuf_grow() in a tight loop of single-character
adds by instead checking strbuf_avail.

Note that we would instead call strbuf_addch directly here,
but it does more work than necessary: it will NUL-terminate
the result for each character read. Instead, in this loop we
read the characters one by one and then add the terminator
manually at the end.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from
(best-of-5):

  real    0m10.948s
  user    0m10.548s
  sys     0m0.412s

to:

  real    0m8.601s
  user    0m8.084s
  sys     0m0.524s

for a wall-clock speedup of 21%.

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>strbuf_getwholeline: use getc_unlocked</title>
<updated>2015-04-16T15:15:04Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2015-04-16T08:49:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=82912d1de86ae3d7f247bc3b16a81afd01aa31c7'/>
<id>urn:sha1:82912d1de86ae3d7f247bc3b16a81afd01aa31c7</id>
<content type='text'>
strbuf_getwholeline calls getc in a tight loop. On modern
libc implementations, the stdio code locks the handle for
every operation, which means we are paying a significant
overhead.  We can get around this by locking the handle for
the whole loop and using the unlocked variant.

Running "git rev-parse refs/heads/does-not-exist" on a repo
with an extremely large (1.6GB) packed-refs file went from:

  real    0m18.900s
  user    0m18.472s
  sys     0m0.448s

to:

  real    0m10.953s
  user    0m10.384s
  sys     0m0.580s

for a wall-clock speedup of 42%. All times are best-of-3,
and done on a glibc 2.19 system.

Note that we call into strbuf_grow while holding the lock.
It's possible for that function to call other stdio
functions (e.g., printing to stderr when dying due to malloc
error); however, the POSIX.1-2001 definition of flockfile
makes it clear that the locks are per-handle, so we are fine
unless somebody else tries to read from our same handle.
This doesn't ever happen in the current code, and is
unlikely to be added in the future (we would have to do
something exotic like add a die_routine that tried to read
from stdin).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
