git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
CPClément Poulain <clement.poulain@ensimag.imag.fr>
Date
Jun 6, 2010, 11:30 UTC
Message-ID
<1275823848-7151-2-git-send-email-clement.poulain@ensimag.imag.fr>
In-Reply-To
<1275823848-7151-1-git-send-email-clement.poulain@ensimag.imag.fr>
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@ensimag.imag.fr>
Signed-off-by: Diane Gasselin <diane.gasselin@ensimag.imag.fr>
Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr>
---
 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
Previous: Clément PoulainNext: Clément Poulain
Message 2 of 8 in “git-gui blame: use textconv”
  1. 0/4 git-gui blame: use textconvClément Poulain, Jun 6, 2010
  2. 1/4 sha1_name: creating context cacheClément Poulain, Jun 6, 2010
  3. 2/4 textconv: support for cat-fileClément Poulain, Jun 6, 2010
  4. 3/4 git-gui: use textconv filter for diff and blameClément Poulain, Jun 6, 2010
  5. 4/4 t/t8007: test textconv support for cat-fileClément Poulain, Jun 6, 2010
  6. Matthieu MoyJun 6, 2010
  7. Jeff KingJun 6, 2010
  8. Clément PoulainJun 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.