aboutsummaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-10 12:02:54 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-10 12:37:54 -0700
commit2e83b66c32c1d482575fd8caed80680a2f69c5f1 (patch)
tree8b3fc22561a43f5abf81c4c6c88a194dc58180dd /sha1_name.c
parent9619617d33c83ad873539384b3cbfd564053be76 (diff)
downloadgit-2e83b66c32c1d482575fd8caed80680a2f69c5f1.tar.gz
git-2e83b66c32c1d482575fd8caed80680a2f69c5f1.tar.xz
fix overslow :/no-such-string-ever-existed diagnostics
"git cmd :/no-such-string-ever-existed" runs an extra round of get_sha1() since 009fee4 (Detailed diagnosis when parsing an object name fails., 2009-12-07). Once without error diagnosis to see there is no commit with such a string in the log message (hence "it cannot be a ref"), and after seeing that :/no-such-string-ever-existed is not a filename (hence "it cannot be a path, either"), another time to give "better diagnosis". The thing is, the second time it runs, we already know that traversing the history all the way down to the root will _not_ find any matching commit. Rename misguided "gently" parameter, which is turned off _only_ when the "detailed diagnosis" codepath knows that it cannot be a ref and making the call only for the caller to die with a message. Flip its meaning (and adjust the callers) and call it "only_to_die", which is not a great name, but it describes far more clearly what the codepaths that switches their behaviour based on this variable do. On my box, the command spends ~1.8 seconds without the patch to make the report; with the patch it spends ~1.12 seconds. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 90d8bfa20..ec836117d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1080,11 +1080,12 @@ 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 only_to_die, const char *prefix)
{
struct object_context oc;
int ret;
- ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
+ ret = get_sha1_with_context_1(name, sha1, &oc, only_to_die, prefix);
*mode = oc.mode;
return ret;
}
@@ -1108,7 +1109,7 @@ static char *resolve_relative_path(const char *rel)
int get_sha1_with_context_1(const char *name, unsigned char *sha1,
struct object_context *oc,
- int gently, const char *prefix)
+ int only_to_die, const char *prefix)
{
int ret, bracket_depth;
int namelen = strlen(name);
@@ -1130,7 +1131,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
struct cache_entry *ce;
char *new_path = NULL;
int pos;
- if (namelen > 2 && name[1] == '/') {
+ if (!only_to_die && namelen > 2 && name[1] == '/') {
struct commit_list *list = NULL;
for_each_ref(handle_one_ref, &list);
return get_sha1_oneline(name + 2, sha1, list);
@@ -1173,7 +1174,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
}
pos++;
}
- if (!gently && name[1] && name[1] != '/')
+ if (only_to_die && name[1] && name[1] != '/')
diagnose_invalid_index_path(stage, prefix, cp);
free(new_path);
return -1;
@@ -1189,7 +1190,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
if (*cp == ':') {
unsigned char tree_sha1[20];
char *object_name = NULL;
- if (!gently) {
+ if (only_to_die) {
object_name = xmalloc(cp-name+1);
strncpy(object_name, name, cp-name);
object_name[cp-name] = '\0';
@@ -1202,7 +1203,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
if (new_filename)
filename = new_filename;
ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
- if (!gently) {
+ if (only_to_die) {
diagnose_invalid_sha1_path(prefix, filename,
tree_sha1, object_name);
free(object_name);
@@ -1215,7 +1216,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
free(new_filename);
return ret;
} else {
- if (!gently)
+ if (only_to_die)
die("Invalid object name '%s'.", object_name);
}
}