Add caching of message digests for objects.
PATCH 2/6 Add caching of message digests for objects.
Message digests are created when git objects are created. The digests are stored in either their own files or in an "mds" file that goes with a pack file's index file. Most of the changes are in sha1_file.c, with a function to create an mds file in pack-write.c. Macros in cache.h allow the previous function calls to be used - some now take a pointer to a digest as an argument. Hex.c was modified to print message digests in hexadecimal, and a test script was modified to account for a new directory in objects.
--- Makefile | 121 ++++++++++++ builtin/init-db.c | 17 ++ cache.h | 72 ++++++- environment.c | 57 ++++++ git.c | 14 ++- hex.c | 106 ++++++++++- pack-write.c | 120 ++++++++++++ pack.h | 3 + sha1_file.c | 560 +++++++++++++++++++++++++++++++++++++++++++++++------ t/t0000-basic.sh | 13 +- 10 files changed, 1012 insertions(+), 71 deletions(-)
Makefile +121 -0
@@ -278,6 +278,92 @@ all:: # dependency rules. # # Define NATIVE_CRLF if your platform uses CRLF for line endings. +# +# +# Set MDSDB to indicate the database type for the DB mapping SHA1 +# values to the MDs (Message Digests) of the objects git stores. +# Valid values are: +# +# 0 for storing each local-object MD in its own file. +# +# [more to be added as needed - a legal value is mandatory]. +# +# Note: the values for MDSDB are determined by preprocessor directives +# defined in mdsdb.h This constant must be defined so that necessary +# files are compiled. +# +MDSDB = 0 + +# +# Define MDIGEST_DEFAULT to set the default type of MD for authentication and +# hash-collision detection. Legal values +# are: +# MDIGEST_CRC - use a CRC (used only as a minimal digest for performance +# testing). +# +# MDIGEST_SHA1 - use a SHA-1 digest. +# +# MDIGEST_SHA256 - use a SHA-256 digest. +# +# MDIGEST_SHA512 - use a SHA-512 digest. +# +# (additional ones may be added as needed.) +# +# Note: the message digests computed are for uncompressed objects, not +# including the Git object-header. If not set, a default defined in the +# file mdigest.h will be used. +# +MDIGEST_DEFAULT = MDIGEST_SHA256 + +# +# Define PACKDB to use a GDBM-like database for storing message +# digests compactly when those digests are not available using the +# normal mechanisms. As an example, if an alternate object database +# is used and if it was created using an older version of git, message +# digests may not be available, and git by design cannot modify an +# alternate object database, so the message digests cannot be added to +# it. If PACKDB is not defined, at certain points (e.g., during a +# commit, the digest for an object in an alternate object database +# will be calculated each time. When PACKDB is defined, the object's +# digest is calculated once and stored in the packdb database. GDBM +# is too slow for use in general, but it is adequate for handling +# unusual cases. +# +# Valid values are: +# +# 0 - use GDBM to implement the database. +# [not defined] - do nothing. +# +# [more can be added as needed]. +# +PACKDB = + +# Define PACKDB_TEST in order to turn on an inefficient +# test for PACKDB functions. This code will add an entry to the packdb +# database during commits when such an entry is not necessary and then +# will read it back to make sure the data was added correctly. The option +# has no effect if PACKDB is not defined. +# +# NOTE: this option should not be used in a released version of Git. +# +PACKDB_TEST = + +# Define COMMIT_DIGEST to include a 'digest' header in a commit. The header +# will contain a 2-character code indicating the digest type, followed +# immediately by the digest. We are delaying turning this on by default +# until the test scripts are updated, as the test scripts include explicit +# file lengths and SHA-1 values. + +COMMIT_DIGEST = + +# Define COMMIT_DIGEST_TEST to force get_objects_mds to be called even if +# COMMIT_DIGEST is not defined (in which case the digest header will not +# appear in the commit object created). +# +# NOTE: this option should not be used in a released version of Git. +# + +COMMIT_DIGEST_TEST = GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -536,7 +622,9 @@ LIB_H += blob.h LIB_H += builtin.h LIB_H += bulk-checkin.h LIB_H += cache.h +LIB_H += mdigest.h LIB_H += cache-tree.h +LIB_H += mdsdb.h LIB_H += color.h LIB_H += commit.h LIB_H += compat/bswap.h
@@ -711,6 +799,7 @@ LIB_OBJS += sequencer.o LIB_OBJS += sha1-array.o LIB_OBJS += sha1-lookup.o LIB_OBJS += sha1_file.o +LIB_OBJS += mdigest.o LIB_OBJS += sha1_name.o LIB_OBJS += shallow.o LIB_OBJS += sideband.o
@@ -836,6 +925,7 @@ BUILTIN_OBJS += builtin/write-tree.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) EXTLIBS = + # # Platform specific tweaks #
@@ -1721,6 +1811,37 @@ ifeq ($(PYTHON_PATH),) NO_PYTHON=NoThanks endif +ifdef MDSDB +BASIC_CFLAGS += -DBLOB_MDS_CHECK +endif + +ifdef COMMIT_DIGEST +BASIC_CFLAGS += -DCOMMIT_DIGEST +endif + +ifdef COMMIT_DIGEST_TEST +BASIC_CFLAGS += -DCOMMIT_DIGEST_TEST +endif + +ifdef MDIGEST_DEFAULT +BASIC_CFLAGS += -DMDIGEST_DEFAULT=$(MDIGEST_DEFAULT) +endif + +ifeq ($(MDSDB), 0) +BASIC_CFLAGS += -DMDSDB=$(MDSDB) +LIB_OBJS += objd-mdsdb.o +endif + +ifeq ($(PACKDB), 0) +BASIC_CFLAGS += -DPACKDB +LIB_OBJS += gdbm-packdb.o +EXTLIBS += -lgdbm +endif + +ifdef PACKDB_TEST +BASIC_CFLAGS += -DPACKDB_TEST +endif + QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir QUIET_SUBDIR1 =
builtin/init-db.c +17 -0
@@ -7,6 +7,10 @@#include "builtin.h" #include "exec_cmd.h" #include "parse-options.h" +#include "mdsdb.h" +#ifdef PACKDB +#include "packdb.h" +#endif #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -309,6 +313,19 @@ static void create_object_directory(void)strcpy (path+len,"/info" );safe_create_dir (path,1 ); +#if (MDSDB ==0 ) +strcpy (path+len,"/mdsd" ); +safe_create_dir (path,1 ); +#endif +/* +* In case the call in environent.c failed to initialize +* (missing directory?) or somehow wasn't called at all. +*/ +mdsdb_init (); +mdigest_init (); +#ifdef PACKDB +packdb_init (); +#endif free (path); }
cache.h +64 -8
150 lines not on this page · raw message
environment.c +57 -0
93 lines not on this page · raw message
git.c +13 -1
@@ -4,7 +4,10 @@#include "help.h" #include "quote.h" #include "run-command.h" - +#include "mdsdb.h" +#ifdef PACKDB +#include "packdb.h" +#endif const char git_usage_string[] ="git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n" " [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"
@@ -279,6 +282,15 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)struct stat st;const char *prefix; +static int mdsdb_need_atexit =1 ; + +if (mdsdb_need_atexit) { +#ifdef PACKDB +atexit (packdb_finish); +#endif +atexit (mdsdb_finish); + mdsdb_need_atexit =0 ; + } prefix =NULL ; help = argc ==2 && !strcmp (argv[1 ],"-h" );if (!help) {
hex.c +105 -1
121 lines not on this page · raw message
pack-write.c +120 -0
146 lines not on this page · raw message
pack.h +3 -0
@@ -70,6 +70,8 @@ struct pack_idx_entry {unsigned char sha1[20 ];uint32_t crc32;off_t offset; +int has_digest; +mdigest_t digest; };
@@ -77,6 +79,7 @@ struct progress;typedef int (*verify_fn )(const unsigned char *,enum object_type ,unsigned long ,void *,int *);extern const char *write_idx_file (const char *index_name,struct pack_idx_entry **objects,int nr_objects,const struct pack_idx_option *,unsigned char *sha1); +extern const char *write_mds_file (const char *mds_name,struct pack_idx_entry **objects,int nr_objects,const struct pack_idx_option *,unsigned char *sha1);extern int check_pack_crc (struct packed_git *p,struct pack_window **w_curs,off_t offset,off_t len,unsigned int nr);extern int verify_pack_index (struct packed_git *);extern int verify_pack (struct packed_git *,verify_fn fn,struct progress *,uint32_t );
sha1_file.c +505 -55
864 lines not on this page · raw message
t/t0000-basic.sh +7 -6
@@ -34,17 +34,18 @@ fi # git init has been done in an empty repository. # make sure it is empty. -find .git/objects -type f -print >should-be-empty +find .git/objects -type f -a ! -name mdsd -a ! -name packdb -print >should-be-empty test_expect_success \ '.git/objects should be empty after git init in an empty repo.' \ 'cmp -s /dev/null should-be-empty' -# also it should have 2 subdirectories; no fan-out anymore, pack, and info. -# 3 is counting "objects" itself -find .git/objects -type d -print >full-of-directories +# also it should have 3 subdirectories; +# no fan-out anymore, pack, and info and mdsd. +# 4 (listed by find) is the result of counting "objects" as well. +find .git/objects \( -type d -o -name mdsd \) -print >full-of-directories test_expect_success \ - '.git/objects should have 3 subdirectories.' \ - 'test $(wc -l < full-of-directories) = 3' + '.git/objects should have 3 subdirectories or files.' \ + 'test $(wc -l < full-of-directories) = 4' ################################################################ # Test harness
Signature · 1 line
1.7.1