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>
This commit is contained in:
parent
37d29e1051
commit
573285e552
11
cache.h
11
cache.h
@ -730,12 +730,23 @@ static inline unsigned int hexval(unsigned char c)
|
|||||||
#define MINIMUM_ABBREV 4
|
#define MINIMUM_ABBREV 4
|
||||||
#define DEFAULT_ABBREV 7
|
#define DEFAULT_ABBREV 7
|
||||||
|
|
||||||
|
struct object_context {
|
||||||
|
unsigned char tree[20];
|
||||||
|
char path[PATH_MAX];
|
||||||
|
unsigned mode;
|
||||||
|
};
|
||||||
|
|
||||||
extern int get_sha1(const char *str, unsigned char *sha1);
|
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);
|
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)
|
static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
|
||||||
{
|
{
|
||||||
return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
|
return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
|
||||||
}
|
}
|
||||||
|
extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int gently, const char *prefix);
|
||||||
|
static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
|
||||||
|
{
|
||||||
|
return get_sha1_with_context_1(str, sha1, orc, 1, NULL);
|
||||||
|
}
|
||||||
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
|
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
|
||||||
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
||||||
extern int read_ref(const char *filename, unsigned char *sha1);
|
extern int read_ref(const char *filename, unsigned char *sha1);
|
||||||
|
31
sha1_name.c
31
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)
|
int get_sha1(const char *name, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
unsigned unused;
|
struct object_context unused;
|
||||||
return get_sha1_with_mode(name, sha1, &unused);
|
return get_sha1_with_context(name, sha1, &unused);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Must be called only when object_name:filename doesn't exist. */
|
/* Must be called only when object_name:filename doesn't exist. */
|
||||||
@ -1031,12 +1031,24 @@ 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)
|
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 ret, bracket_depth;
|
||||||
int namelen = strlen(name);
|
int namelen = strlen(name);
|
||||||
const char *cp;
|
const char *cp;
|
||||||
|
|
||||||
*mode = S_IFINVALID;
|
memset(oc, 0, sizeof(*oc));
|
||||||
|
oc->mode = S_IFINVALID;
|
||||||
ret = get_sha1_1(name, namelen, sha1);
|
ret = get_sha1_1(name, namelen, sha1);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return ret;
|
return ret;
|
||||||
@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
|
|||||||
cp = name + 3;
|
cp = name + 3;
|
||||||
}
|
}
|
||||||
namelen = namelen - (cp - name);
|
namelen = namelen - (cp - name);
|
||||||
|
|
||||||
|
strncpy(oc->path, cp,
|
||||||
|
sizeof(oc->path));
|
||||||
|
oc->path[sizeof(oc->path)-1] = '\0';
|
||||||
|
|
||||||
if (!active_cache)
|
if (!active_cache)
|
||||||
read_cache();
|
read_cache();
|
||||||
pos = cache_name_pos(cp, namelen);
|
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;
|
break;
|
||||||
if (ce_stage(ce) == stage) {
|
if (ce_stage(ce) == stage) {
|
||||||
hashcpy(sha1, ce->sha1);
|
hashcpy(sha1, ce->sha1);
|
||||||
*mode = ce->ce_mode;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pos++;
|
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)) {
|
if (!get_sha1_1(name, cp-name, tree_sha1)) {
|
||||||
const char *filename = cp+1;
|
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) {
|
if (!gently) {
|
||||||
diagnose_invalid_sha1_path(prefix, filename,
|
diagnose_invalid_sha1_path(prefix, filename,
|
||||||
tree_sha1, object_name);
|
tree_sha1, object_name);
|
||||||
free(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;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
if (!gently)
|
if (!gently)
|
||||||
|
Loading…
Reference in New Issue
Block a user