Skip to content

support reading and writing uncompressed loose object

Liu Yubao git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5avoid parse_sha1_header() accessing memory out of boundsha1_file.c+9 -62 replies
2/5don't die immediately when convert an invalid type nameobject.c object.h sha1_file.c+15 -20 replies
3/5optimize parse_sha1_header() a little by detecting object typesha1_file.c+4 -12 replies
4/5support reading uncompressed loose objectsha1_file.c+19 -12 replies
5/5support writing uncompressed loose objectsha1_file.c+12 -42 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] support reading and writing uncompressed loose object

Hi,

In original implementation, git stores loose object like this:
loose object = deflate(typename + <space> + size + data)

The patches below add support to read and write uncompressed loose object:
loose object = typename + <space> + size + data

The cons and pros to use uncompressed loose object:

cons
* old git can't read these uncompressed loose objects (I think it's not a big problem because old git can read pack files generated by new git)

* uncompressed loose objects occupy more disk space (I also think it's not a big problem because loose objects aren't too many in general)

pros
* avoid compressing and uncompressing loose objects that are likely frequently used when coding/merging with git add/diff/diff --cached/ merge/rebase/log.

* the code to read and write uncompressed loose objects is simpler, although there are now more code paths for compatibility.

* better to share loose objects among multiple git processes because sha1 files can be used directly after mmapped. The original git uncompresses loose objects into heap memory area so that they can't be shared by other processes.
(NOTICE: The patches below doesn't use mmapped sha1 files directly
because I find parse_object() requires a buffer terminated with zero.)

* easy to grep objects in .git/objects (...stupid use case :-)

If these patches are worth being included into upstream branch, I will add a new config variable core.uncompressedLooseObject.

Explanation to the patches:

1) avoid parse_sha1_header() accessing memory out of bound Just for more safety, no inflateInit() to detect errors for uncompressed loose objects.

2) don't die immediately when convert an invalid type name So we can fall back to compressed loose objects.

3) optimize parse_sha1_header() a little by detecting object type To quickly detect whether it seems an uncompressed loose object.

4) support reading uncompressed loose object
The new feature.

5) support writing uncompressed loose object The new feature, need a git-config variable yet.

The patches are generated against git-1.6.1-rc, I have run the test cases and it seems ok.

 object.c    |   14 +++++++++++++-
 object.h    |    1 +
 sha1_file.c |   58 +++++++++++++++++++++++++++++++++++++++++++++-------------
 3 files changed, 59 insertions(+), 14 deletions(-)