<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/commit.c, branch v2.0.3</title>
<subtitle>Fork of git SCM with my patches.</subtitle>
<id>http://git.kilabit.info/git/atom?h=v2.0.3</id>
<link rel='self' href='http://git.kilabit.info/git/atom?h=v2.0.3'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/'/>
<updated>2014-07-22T17:25:17Z</updated>
<entry>
<title>Merge branch 'bg/xcalloc-nmemb-then-size' into maint</title>
<updated>2014-07-22T17:25:17Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2014-07-22T17:25:17Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=cfececfe1ff1554783030a6f08b431ad50263800'/>
<id>urn:sha1:cfececfe1ff1554783030a6f08b431ad50263800</id>
<content type='text'>
* bg/xcalloc-nmemb-then-size:
  transport-helper.c: rearrange xcalloc arguments
  remote.c: rearrange xcalloc arguments
  reflog-walk.c: rearrange xcalloc arguments
  pack-revindex.c: rearrange xcalloc arguments
  notes.c: rearrange xcalloc arguments
  imap-send.c: rearrange xcalloc arguments
  http-push.c: rearrange xcalloc arguments
  diff.c: rearrange xcalloc arguments
  config.c: rearrange xcalloc arguments
  commit.c: rearrange xcalloc arguments
  builtin/remote.c: rearrange xcalloc arguments
  builtin/ls-remote.c: rearrange xcalloc arguments
</content>
</entry>
<entry>
<title>reuse cached commit buffer when parsing signatures</title>
<updated>2014-06-13T19:10:13Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-13T06:32:11Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=218aa3a6162b80696a82b8745daa38fa826985ae'/>
<id>urn:sha1:218aa3a6162b80696a82b8745daa38fa826985ae</id>
<content type='text'>
When we call show_signature or show_mergetag, we read the
commit object fresh via read_sha1_file and reparse its
headers. However, in most cases we already have the object
data available, attached to the "struct commit". This is
partially laziness in dealing with the memory allocation
issues, but partially defensive programming, in that we
would always want to verify a clean version of the buffer
(not one that might have been munged by other users of the
commit).

However, we do not currently ever munge the commit buffer,
and not using the already-available buffer carries a fairly
big performance penalty when we are looking at a large
number of commits. Here are timings on linux.git:

  [baseline, no signatures]
  $ time git log &gt;/dev/null
  real    0m4.902s
  user    0m4.784s
  sys     0m0.120s

  [before]
  $ time git log --show-signature &gt;/dev/null
  real    0m14.735s
  user    0m9.964s
  sys     0m0.944s

  [after]
  $ time git log --show-signature &gt;/dev/null
  real    0m9.981s
  user    0m5.260s
  sys     0m0.936s

Note that our user CPU time drops almost in half, close to
the non-signature case, but we do still spend more
wall-clock and system time, presumably from dealing with
gpg.

An alternative to this is to note that most commits do not
have signatures (less than 1% in this repo), yet we pay the
re-parsing cost for every commit just to find out if it has
a mergetag or signature. If we checked that when parsing the
commit initially, we could avoid re-examining most commits
later on. Even if we did pursue that direction, however,
this would still speed up the cases where we _do_ have
signatures. So it's probably worth doing either way.

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>commit: record buffer length in cache</title>
<updated>2014-06-13T19:09:38Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:44:13Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=8597ea3afea067b39ba7d4adae7ec6c1ee0e7c91'/>
<id>urn:sha1:8597ea3afea067b39ba7d4adae7ec6c1ee0e7c91</id>
<content type='text'>
Most callsites which use the commit buffer try to use the
cached version attached to the commit, rather than
re-reading from disk. Unfortunately, that interface provides
only a pointer to the NUL-terminated buffer, with no
indication of the original length.

For the most part, this doesn't matter. People do not put
NULs in their commit messages, and the log code is happy to
treat it all as a NUL-terminated string. However, some code
paths do care. For example, when checking signatures, we
want to be very careful that we verify all the bytes to
avoid malicious trickery.

This patch just adds an optional "size" out-pointer to
get_commit_buffer and friends. The existing callers all pass
NULL (there did not seem to be any obvious sites where we
could avoid an immediate strlen() call, though perhaps with
some further refactoring we could).

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>commit: convert commit-&gt;buffer to a slab</title>
<updated>2014-06-13T19:08:17Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:43:02Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=c1b3c71f4b4571abb2b2a457122fd100dc9f7eb0'/>
<id>urn:sha1:c1b3c71f4b4571abb2b2a457122fd100dc9f7eb0</id>
<content type='text'>
This will make it easier to manage the buffer cache
independently of the "struct commit" objects. It also
shrinks "struct commit" by one pointer, which may be
helpful.

Unfortunately it does not reduce the max memory size of
something like "rev-list", because rev-list uses
get_cached_commit_buffer() to decide not to show each
commit's output (and due to the design of slab_at, accessing
the slab requires us to extend it, allocating exactly the
same number of buffer pointers we dropped from the commit
structs).

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>use get_commit_buffer to avoid duplicate code</title>
<updated>2014-06-13T19:08:17Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:41:02Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=ba41c1c93fd9109eae954f75a8cb8e32c3e29530'/>
<id>urn:sha1:ba41c1c93fd9109eae954f75a8cb8e32c3e29530</id>
<content type='text'>
For both of these sites, we already do the "fallback to
read_sha1_file" trick. But we can shorten the code by just
using get_commit_buffer.

Note that the error cases are slightly different when
read_sha1_file fails. get_commit_buffer will die() if the
object cannot be loaded, or is a non-commit.

For get_sha1_oneline, this will almost certainly never
happen, as we will have just called parse_object (and if it
does, it's probably worth complaining about).

For record_author_date, the new behavior is probably better;
we notify the user of the error instead of silently ignoring
it. And because it's used only for sorting by author-date,
somebody examining a corrupt repo can fallback to the
regular traversal order.

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>provide helpers to access the commit buffer</title>
<updated>2014-06-13T19:08:17Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:40:39Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=152ff1ccebd822fd97f27d2a6c3fa2058f088fd8'/>
<id>urn:sha1:152ff1ccebd822fd97f27d2a6c3fa2058f088fd8</id>
<content type='text'>
Many sites look at commit-&gt;buffer to get more detailed
information than what is in the parsed commit struct.
However, we sometimes drop commit-&gt;buffer to save memory,
in which case the caller would need to read the object
afresh. Some callers do this (leading to duplicated code),
and others do not (which opens the possibility of a segfault
if somebody else frees the buffer).

Let's provide a pair of helpers, "get" and "unuse", that let
callers easily get the buffer. They will use the cached
buffer when possible, and otherwise load from disk using
read_sha1_file.

Note that we also need to add a "get_cached" variant which
returns NULL when we do not have a cached buffer. At first
glance this seems to defeat the purpose of "get", which is
to always provide a return value. However, some log code
paths actually use the NULL-ness of commit-&gt;buffer as a
boolean flag to decide whether to try printing the
commit. At least for now, we want to continue supporting
that use.

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>provide a helper to set the commit buffer</title>
<updated>2014-06-13T19:08:17Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:40:14Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=66c2827ea4deb24ff541e30a5b6239ad5e9f6801'/>
<id>urn:sha1:66c2827ea4deb24ff541e30a5b6239ad5e9f6801</id>
<content type='text'>
Right now this is just a one-liner, but abstracting it will
make it easier to change later.

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>provide a helper to free commit buffer</title>
<updated>2014-06-13T19:07:47Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-12T22:05:37Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=0fb370da9ca972f9571530f95c0dacb31368c280'/>
<id>urn:sha1:0fb370da9ca972f9571530f95c0dacb31368c280</id>
<content type='text'>
This converts two lines into one at each caller. But more
importantly, it abstracts the concept of freeing the buffer,
which will make it easier to change later.

Note that we also need to provide a "detach" mechanism for a
tricky case in index-pack. We are passed a buffer for the
object generated by processing the incoming pack. If we are
not using --strict, we just calculate the sha1 on that
buffer and return, leaving the caller to free it.  But if we
are using --strict, we actually attach that buffer to an
object, pass the object to the fsck functions, and then
detach the buffer from the object again (so that the caller
can free it as usual).  In this case, we don't want to free
the buffer ourselves, but just make sure it is no longer
associated with the commit.

Note that we are making the assumption here that the
attach/detach process does not impact the buffer at all
(e.g., it is never reallocated or modified). That holds true
now, and we have no plans to change that. However, as we
abstract the commit_buffer code, this dependency becomes
less obvious. So when we detach, let's also make sure that
we get back the same buffer that we gave to the
commit_buffer code.

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>commit: push commit_index update into alloc_commit_node</title>
<updated>2014-06-12T17:29:42Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:39:04Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=969eba6341a5af8ac52c67e26462548ed05e23e3'/>
<id>urn:sha1:969eba6341a5af8ac52c67e26462548ed05e23e3</id>
<content type='text'>
Whenever we create a commit object via lookup_commit, we
give it a unique index to be used with the commit-slab API.
The theory is that any "struct commit" we create would
follow this code path, so any such struct would get an
index. However, callers could use alloc_commit_node()
directly (and get multiple commits with index 0).

Let's push the indexing into alloc_commit_node so that it's
hard for callers to get it wrong.

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>commit_tree: take a pointer/len pair rather than a const strbuf</title>
<updated>2014-06-12T17:29:41Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2014-06-10T21:36:52Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=3ffefb54c0515308ceafb6ba071567d9fd379498'/>
<id>urn:sha1:3ffefb54c0515308ceafb6ba071567d9fd379498</id>
<content type='text'>
While strbufs are pretty common throughout our code, it is
more flexible for functions to take a pointer/len pair than
a strbuf. It's easy to turn a strbuf into such a pair (by
dereferencing its members), but less easy to go the other
way (you can strbuf_attach, but that has implications about
memory ownership).

This patch teaches commit_tree (and its associated callers
and sub-functions) to take such a pair for the commit
message rather than a strbuf.  This makes passing the buffer
around slightly more verbose, but means we can get rid of
some dangerous strbuf_attach calls in the next patch.

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