Commit ccfe88e6ed61166face3636161962cb7c852e047

Stefan Sperling 2018-07-13T00:39:26

provide a compile-time toggle for object caching

diff --git a/got/Makefile b/got/Makefile
index 3462401..3227043 100644
--- a/got/Makefile
+++ b/got/Makefile
@@ -18,6 +18,7 @@ DEBUG = -O0 -g
 .endif
 CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
 #CPLAGS += -DGOT_PACK_NO_MMAP
+#CFLAGS += -DGOT_NO_OBJ_CACHE
 
 # For now, default to installing binary in ~/bin
 GROUP!=id -g -n
diff --git a/lib/repository.c b/lib/repository.c
index c0e12e9..4cda42e 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -149,6 +149,7 @@ done:
 
 }
 
+#ifndef GOT_NO_OBJ_CACHE
 static const struct got_error *
 cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
 {
@@ -191,6 +192,7 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
 		ce->data.commit = (struct got_commit_object *)item;
 		break;
 	}
+
 	err = got_object_idcache_add(cache->idcache, id, ce);
 	if (err) {
 		if (err->code == GOT_ERR_OBJ_EXISTS) {
@@ -198,21 +200,21 @@ cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
 			err = NULL;
 		}
 	}
-
 	return err;
 }
+#endif
 
 const struct got_error *
 got_repo_cache_object(struct got_repository *repo, struct got_object_id *id,
     struct got_object *obj)
 {
+#ifndef GOT_NO_OBJ_CACHE
 	const struct got_error *err = NULL;
-
 	err = cache_add(&repo->objcache, id, obj);
 	if (err)
 		return err;
-
 	obj->refcnt++;
+#endif
 	return NULL;
 }
 
@@ -236,13 +238,13 @@ const struct got_error *
 got_repo_cache_tree(struct got_repository *repo, struct got_object_id *id,
     struct got_tree_object *tree)
 {
+#ifndef GOT_NO_OBJ_CACHE
 	const struct got_error *err = NULL;
-
 	err = cache_add(&repo->treecache, id, tree);
 	if (err)
 		return err;
-
 	tree->refcnt++;
+#endif
 	return NULL;
 }
 
@@ -266,13 +268,14 @@ const struct got_error *
 got_repo_cache_commit(struct got_repository *repo, struct got_object_id *id,
     struct got_commit_object *commit)
 {
+#ifndef GOT_NO_OBJ_CACHE
 	const struct got_error *err = NULL;
-
 	err = cache_add(&repo->commitcache, id, commit);
 	if (err)
 		return err;
 
 	commit->refcnt++;
+#endif
 	return NULL;
 }
 
diff --git a/regress/repository/Makefile b/regress/repository/Makefile
index 5c429a7..42b06ff 100644
--- a/regress/repository/Makefile
+++ b/regress/repository/Makefile
@@ -10,6 +10,7 @@ LDADD = -lutil -lz
 DEBUG = -O0 -g
 CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
 #CFLAGS += -DGOT_PACK_NO_MMAP
+#CFLAGS += -DGOT_NO_OBJ_CACHE
 
 NOMAN = yes
 
diff --git a/regress/worktree/Makefile b/regress/worktree/Makefile
index f8c274e..9d0e62f 100644
--- a/regress/worktree/Makefile
+++ b/regress/worktree/Makefile
@@ -10,6 +10,7 @@ LDADD = -lutil -lz
 DEBUG = -O0 -g
 CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
 #CFLAGS += -DGOT_PACK_NO_MMAP
+#CFLAGS += -DGOT_NO_OBJ_CACHE
 
 NOMAN = yes
 
diff --git a/tog/Makefile b/tog/Makefile
index dbaa942..ae193fb 100644
--- a/tog/Makefile
+++ b/tog/Makefile
@@ -18,6 +18,7 @@ DEBUG = -O0 -g
 .endif
 CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
 #CPLAGS += -DGOT_PACK_NO_MMAP
+#CFLAGS += -DGOT_NO_OBJ_CACHE
 
 # For now, default to installing binary in ~/bin
 GROUP!=id -g -n