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>
Clément Poulain committed
Jun 9, 2010 at 19:02 UTC
573285e55265ccedab5507c47ebd4357f360093f
2 files changed
+37
-5
cache.h
+11
@@ -730,12 +730,23 @@ static inline unsigned int hexval(unsigned char c)
730
#define MINIMUM_ABBREV 4
731
#define DEFAULT_ABBREV 7
732
733
+struct object_context {
734
+ unsigned char tree[20];
735
+ char path[PATH_MAX];
736
+ unsigned mode;
737
+};
738
+
739
extern int get_sha1(const char *str, unsigned char *sha1);
740
extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
741
static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
742
{
743
return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
744
}
745
+extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int gently, const char *prefix);
746
+static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
747
+{
748
+ return get_sha1_with_context_1(str, sha1, orc, 1, NULL);
749
+}
750
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
751
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
752
extern int read_ref(const char *filename, unsigned char *sha1);
sha1_name.c
+26
-5
@@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
933
*/
934
int get_sha1(const char *name, unsigned char *sha1)
935
{
936
- unsigned unused;
937
- return get_sha1_with_mode(name, sha1, &unused);
936
+ struct object_context unused;
937
+ return get_sha1_with_context(name, sha1, &unused);
938
}
939
940
/* Must be called only when object_name:filename doesn't exist. */
@@ -1031,12 +1031,24 @@ static void diagnose_invalid_index_path(int stage,
1031
1032
1033
int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
1034
+{
1035
+ struct object_context oc;
1036
+ int ret;
1037
+ ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
1038
+ *mode = oc.mode;
1039
+ return ret;
1040
+}
1041
+
1042
+int get_sha1_with_context_1(const char *name, unsigned char *sha1,
1043
+ struct object_context *oc,
1044
+ int gently, const char *prefix)
1045
{
1046
int ret, bracket_depth;
1047
int namelen = strlen(name);
1048
const char *cp;
1049
1039
- *mode = S_IFINVALID;
1050
+ memset(oc, 0, sizeof(*oc));
1051
+ oc->mode = S_IFINVALID;
1052
ret = get_sha1_1(name, namelen, sha1);
1053
if (!ret)
1054
return ret;
@@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1071
cp = name + 3;
1072
}
1073
namelen = namelen - (cp - name);
1074
+
1075
+ strncpy(oc->path, cp,
1076
+ sizeof(oc->path));
1077
+ oc->path[sizeof(oc->path)-1] = '\0';
1078
+
1079
if (!active_cache)
1080
read_cache();
1081
pos = cache_name_pos(cp, namelen);
@@ -1071,7 +1088,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1088
break;
1089
if (ce_stage(ce) == stage) {
1090
hashcpy(sha1, ce->sha1);
1074
- *mode = ce->ce_mode;
1091
return 0;
1092
}
1093
pos++;
@@ -1098,12 +1114,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1114
}
1115
if (!get_sha1_1(name, cp-name, tree_sha1)) {
1116
const char *filename = cp+1;
1101
- ret = get_tree_entry(tree_sha1, filename, sha1, mode);
1117
+ ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
1118
if (!gently) {
1119
diagnose_invalid_sha1_path(prefix, filename,
1120
tree_sha1, object_name);
1121
free(object_name);
1122
}
1123
+ hashcpy(oc->tree, tree_sha1);
1124
+ strncpy(oc->path, filename,
1125
+ sizeof(oc->path));
1126
+ oc->path[sizeof(oc->path)-1] = '\0';
1127
+
1128
return ret;
1129
} else {
1130
if (!gently)