From: "Clément Poulain" <clement.poulain@ensimag.imag.fr>
To: git@vger.kernel.org
Cc: spearce@spearce.org, drizzd@aon.at, matthieu.moy@grenoble-inp.fr,
"Clément Poulain" <clement.poulain@ensimag.imag.fr>,
"Diane Gasselin" <diane.gasselin@ensimag.imag.fr>,
"Axel Bonnet" <axel.bonnet@ensimag.imag.fr>
Subject: [RFC/PATCH 1/4] sha1_name: creating context cache
Date: Sun, 6 Jun 2010 13:30:45 +0200 [thread overview]
Message-ID: <1275823848-7151-2-git-send-email-clement.poulain@ensimag.imag.fr> (raw)
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
next prev parent reply other threads:[~2010-06-06 11:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-06 11:30 [RFC/PATCH 0/4] git-gui blame: use textconv Clément Poulain
2010-06-06 11:30 ` Clément Poulain [this message]
2010-06-06 11:30 ` [RFC/PATCH 2/4] textconv: support for cat-file Clément Poulain
2010-06-06 11:30 ` [RFC/PATCH 3/4] git-gui: use textconv filter for diff and blame Clément Poulain
2010-06-06 11:30 ` [RFC/PATCH 4/4] t/t8007: test textconv support for cat-file Clément Poulain
2010-06-06 15:56 ` [RFC/PATCH 1/4] sha1_name: creating context cache Matthieu Moy
2010-06-06 22:15 ` Jeff King
2010-06-07 8:34 ` Clément Poulain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275823848-7151-2-git-send-email-clement.poulain@ensimag.imag.fr \
--to=clement.poulain@ensimag.imag.fr \
--cc=axel.bonnet@ensimag.imag.fr \
--cc=diane.gasselin@ensimag.imag.fr \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=matthieu.moy@grenoble-inp.fr \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).