Skip to content

Commit 8c135ea

Browse files
committed
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 <[email protected]>
1 parent f01cc14 commit 8c135ea

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

cache.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,8 @@ struct object_context {
812812
};
813813

814814
extern int get_sha1(const char *str, unsigned char *sha1);
815-
extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int only_to_die, const char *prefix);
816-
static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
817-
{
818-
return get_sha1_with_mode_1(str, sha1, mode, 0, NULL);
819-
}
815+
extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode);
816+
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
820817
extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc);
821818

822819
/*

setup.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,14 @@ int check_filename(const char *prefix, const char *arg)
5555

5656
static void NORETURN die_verify_filename(const char *prefix, const char *arg)
5757
{
58-
unsigned char sha1[20];
59-
unsigned mode;
60-
6158
/*
6259
* Saying "'(icase)foo' does not exist in the index" when the
6360
* user gave us ":(icase)foo" is just stupid. A magic pathspec
6461
* begins with a colon and is followed by a non-alnum; do not
65-
* let get_sha1_with_mode_1(only_to_die=1) to even trigger.
62+
* let maybe_die_on_misspelt_object_name() even trigger.
6663
*/
6764
if (!(arg[0] == ':' && !isalnum(arg[1])))
68-
/* try a detailed diagnostic ... */
69-
get_sha1_with_mode_1(arg, sha1, &mode, 1, prefix);
65+
maybe_die_on_misspelt_object_name(arg, prefix);
7066

7167
/* ... or fall back the most general message. */
7268
die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"

sha1_name.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,24 @@ static int get_sha1_with_context_1(const char *name, unsigned char *sha1,
11251125
return ret;
11261126
}
11271127

1128-
int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
1129-
int only_to_die, const char *prefix)
1128+
/*
1129+
* Call this function when you know "name" given by the end user must
1130+
* name an object but it doesn't; the function _may_ die with a better
1131+
* diagnostic message than "no such object 'name'", e.g. "Path 'doc' does not
1132+
* exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
1133+
* you have a chance to diagnose the error further.
1134+
*/
1135+
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
11301136
{
11311137
struct object_context oc;
1132-
int ret;
1133-
ret = get_sha1_with_context_1(name, sha1, &oc, only_to_die, prefix);
1138+
unsigned char sha1[20];
1139+
get_sha1_with_context_1(name, sha1, &oc, 1, prefix);
1140+
}
1141+
1142+
int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
1143+
{
1144+
struct object_context oc;
1145+
int ret = get_sha1_with_context_1(str, sha1, &oc, 0, NULL);
11341146
*mode = oc.mode;
11351147
return ret;
11361148
}

0 commit comments

Comments
 (0)