sha1_name.c: get rid of get_sha1_with_mode_1()
The only external caller is setup.c that tries to give a nicer error message when an object name is misspelt (e.g. "HEAD:cashe.h"). Retire it and give the caller a dedicated and more intuitive API function maybe_die_on_misspelt_object_name(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f01cc14c3c
commit
8c135ea260
7
cache.h
7
cache.h
@ -812,11 +812,8 @@ struct object_context {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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 only_to_die, const char *prefix);
|
extern 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)
|
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
|
||||||
{
|
|
||||||
return get_sha1_with_mode_1(str, sha1, mode, 0, NULL);
|
|
||||||
}
|
|
||||||
extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc);
|
extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
8
setup.c
8
setup.c
@ -55,18 +55,14 @@ int check_filename(const char *prefix, const char *arg)
|
|||||||
|
|
||||||
static void NORETURN die_verify_filename(const char *prefix, const char *arg)
|
static void NORETURN die_verify_filename(const char *prefix, const char *arg)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
|
||||||
unsigned mode;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Saying "'(icase)foo' does not exist in the index" when the
|
* Saying "'(icase)foo' does not exist in the index" when the
|
||||||
* user gave us ":(icase)foo" is just stupid. A magic pathspec
|
* user gave us ":(icase)foo" is just stupid. A magic pathspec
|
||||||
* begins with a colon and is followed by a non-alnum; do not
|
* begins with a colon and is followed by a non-alnum; do not
|
||||||
* let get_sha1_with_mode_1(only_to_die=1) to even trigger.
|
* let maybe_die_on_misspelt_object_name() even trigger.
|
||||||
*/
|
*/
|
||||||
if (!(arg[0] == ':' && !isalnum(arg[1])))
|
if (!(arg[0] == ':' && !isalnum(arg[1])))
|
||||||
/* try a detailed diagnostic ... */
|
maybe_die_on_misspelt_object_name(arg, prefix);
|
||||||
get_sha1_with_mode_1(arg, sha1, &mode, 1, prefix);
|
|
||||||
|
|
||||||
/* ... or fall back the most general message. */
|
/* ... or fall back the most general message. */
|
||||||
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
|
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
|
||||||
|
20
sha1_name.c
20
sha1_name.c
@ -1125,12 +1125,24 @@ static int get_sha1_with_context_1(const char *name, unsigned char *sha1,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
|
/*
|
||||||
int only_to_die, const char *prefix)
|
* Call this function when you know "name" given by the end user must
|
||||||
|
* name an object but it doesn't; the function _may_ die with a better
|
||||||
|
* diagnostic message than "no such object 'name'", e.g. "Path 'doc' does not
|
||||||
|
* exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
|
||||||
|
* you have a chance to diagnose the error further.
|
||||||
|
*/
|
||||||
|
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
|
||||||
{
|
{
|
||||||
struct object_context oc;
|
struct object_context oc;
|
||||||
int ret;
|
unsigned char sha1[20];
|
||||||
ret = get_sha1_with_context_1(name, sha1, &oc, only_to_die, prefix);
|
get_sha1_with_context_1(name, sha1, &oc, 1, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
|
||||||
|
{
|
||||||
|
struct object_context oc;
|
||||||
|
int ret = get_sha1_with_context_1(str, sha1, &oc, 0, NULL);
|
||||||
*mode = oc.mode;
|
*mode = oc.mode;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user