[RFC/PATCH 1/4] sha1_name: creating context cache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This cache keeps the global context for the last sha1 looked up, especially its pathname. The textconv is indeed defined by the diff driver, which is associated with a pathname, not a blob

Signed-off-by: Clément Poulain <clement.poulain@xxxxxxxxxxxxxxx>
Signed-off-by: Diane Gasselin <diane.gasselin@xxxxxxxxxxxxxxx>
Signed-off-by: Axel Bonnet <axel.bonnet@xxxxxxxxxxxxxxx>
---
 builtin/cat-file.c |    3 +++
 cache.h            |    8 ++++++++
 sha1_name.c        |   19 +++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index a933eaa..124e0a9 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -87,6 +87,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 	void *buf;
 	unsigned long size;
 
+	struct strbuf sbuf = STRBUF_INIT;
+
+	object_resolve_context_init(&object_context);
 	if (get_sha1(obj_name, sha1))
 		die("Not a valid object name %s", obj_name);
 
diff --git a/cache.h b/cache.h
index 0f4263c..26a1faf 100644
--- a/cache.h
+++ b/cache.h
@@ -730,6 +730,14 @@ static inline unsigned int hexval(unsigned char c)
 #define MINIMUM_ABBREV 4
 #define DEFAULT_ABBREV 7
 
+struct object_resolve_context {
+	unsigned char tree[20];
+	char path[PATH_MAX];
+	unsigned mode;
+};
+extern struct object_resolve_context object_context;
+void object_resolve_context_init(struct object_resolve_context *orc);
+
 extern int get_sha1(const char *str, unsigned char *sha1);
 extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
 static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
diff --git a/sha1_name.c b/sha1_name.c
index bf92417..093d71a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -7,6 +7,13 @@
 #include "refs.h"
 #include "remote.h"
 
+struct object_resolve_context object_context;
+
+void object_resolve_context_init(struct object_resolve_context *orc)
+{
+	memset(orc, 0, sizeof(*orc));
+}
+
 static int find_short_object_filename(int len, const char *name, unsigned char *sha1)
 {
 	struct alternate_object_database *alt;
@@ -1059,6 +1066,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 			cp = name + 3;
 		}
 		namelen = namelen - (cp - name);
+
+		strncpy(object_context.path, cp,
+			sizeof(object_context.path));
+		object_context.path[sizeof(object_context.path)] = '\0';
+
 		if (!active_cache)
 			read_cache();
 		pos = cache_name_pos(cp, namelen);
@@ -1072,6 +1084,7 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 			if (ce_stage(ce) == stage) {
 				hashcpy(sha1, ce->sha1);
 				*mode = ce->ce_mode;
+				object_context.mode = *mode;
 				return 0;
 			}
 			pos++;
@@ -1104,6 +1117,12 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 							   tree_sha1, object_name);
 				free(object_name);
 			}
+			hashcpy(object_context.tree, tree_sha1);
+			strncpy(object_context.path, filename,
+				sizeof(object_context.path));
+			object_context.path[sizeof(object_context.path)] = '\0';
+			object_context.mode = *mode;
+
 			return ret;
 		} else {
 			if (!gently)
-- 
1.6.6.7.ga5fe3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]