summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorClément Poulain <clement.poulain@ensimag.imag.fr>2010-06-09 19:02:06 +0200
committerJunio C Hamano <gitster@pobox.com>2010-06-18 09:41:29 -0700
commit573285e55265ccedab5507c47ebd4357f360093f (patch)
tree54c1fdbb6e6c347d2df115a51996c60e4f6a285d /sha1_name.c
parent37d29e1051ef8406d21f8b284a659080fcfe3f72 (diff)
downloadgit-573285e55265ccedab5507c47ebd4357f360093f.tar.gz
sha1_name: add get_sha1_with_context()
Textconv is defined by the diff driver, which is associated with a pathname, not a blob. This fonction permits to know the context for the sha1 you're looking for, especially his pathname 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/sha1_name.c b/sha1_name.c
index bf92417838..7fdb20277f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
*/
int get_sha1(const char *name, unsigned char *sha1)
{
- unsigned unused;
- return get_sha1_with_mode(name, sha1, &unused);
+ struct object_context unused;
+ return get_sha1_with_context(name, sha1, &unused);
}
/* Must be called only when object_name:filename doesn't exist. */
@@ -1032,11 +1032,23 @@ static void diagnose_invalid_index_path(int stage,
int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
{
+ struct object_context oc;
+ int ret;
+ ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
+ *mode = oc.mode;
+ return ret;
+}
+
+int get_sha1_with_context_1(const char *name, unsigned char *sha1,
+ struct object_context *oc,
+ int gently, const char *prefix)
+{
int ret, bracket_depth;
int namelen = strlen(name);
const char *cp;
- *mode = S_IFINVALID;
+ memset(oc, 0, sizeof(*oc));
+ oc->mode = S_IFINVALID;
ret = get_sha1_1(name, namelen, sha1);
if (!ret)
return ret;
@@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
cp = name + 3;
}
namelen = namelen - (cp - name);
+
+ strncpy(oc->path, cp,
+ sizeof(oc->path));
+ oc->path[sizeof(oc->path)-1] = '\0';
+
if (!active_cache)
read_cache();
pos = cache_name_pos(cp, namelen);
@@ -1071,7 +1088,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
break;
if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->sha1);
- *mode = ce->ce_mode;
return 0;
}
pos++;
@@ -1098,12 +1114,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
}
if (!get_sha1_1(name, cp-name, tree_sha1)) {
const char *filename = cp+1;
- ret = get_tree_entry(tree_sha1, filename, sha1, mode);
+ ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
if (!gently) {
diagnose_invalid_sha1_path(prefix, filename,
tree_sha1, object_name);
free(object_name);
}
+ hashcpy(oc->tree, tree_sha1);
+ strncpy(oc->path, filename,
+ sizeof(oc->path));
+ oc->path[sizeof(oc->path)-1] = '\0';
+
return ret;
} else {
if (!gently)