X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_name.c;h=be8489e4e5fc98c6e38036a40fb5ca8c0db77ebc;hb=6bc4c72132adbdc06c428f86a96f27e4f8173b99;hp=55f25a2d3b49b1d565a9840b7dcfb2e22687cdd3;hpb=cdd5b82ee8e6941eee9c7b09df63c44789fd5c4b;p=git.git diff --git a/sha1_name.c b/sha1_name.c index 55f25a2d3..be8489e4e 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -76,8 +76,11 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne prepare_packed_git(); for (p = packed_git; p && found < 2; p = p->next) { - uint32_t num = p->num_objects; - uint32_t first = 0, last = num; + uint32_t num, last; + uint32_t first = 0; + open_pack_index(p); + num = p->num_objects; + last = num; while (first < last) { uint32_t mid = (first + last) / 2; const unsigned char *now; @@ -133,6 +136,7 @@ static int find_unique_short_object(int len, char *canonical, int has_unpacked, has_packed; unsigned char unpacked_sha1[20], packed_sha1[20]; + prepare_alt_odb(); has_unpacked = find_short_object_filename(len, canonical, unpacked_sha1); has_packed = find_short_packed_object(len, res, packed_sha1); if (!has_unpacked && !has_packed) @@ -235,23 +239,13 @@ static int ambiguous_path(const char *path, int len) return slash; } -static const char *ref_fmt[] = { - "%.*s", - "refs/%.*s", - "refs/tags/%.*s", - "refs/heads/%.*s", - "refs/remotes/%.*s", - "refs/remotes/%.*s/HEAD", - NULL -}; - int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref) { const char **p, *r; int refs_found = 0; *ref = NULL; - for (p = ref_fmt; *p; p++) { + for (p = ref_rev_parse_rules; *p; p++) { unsigned char sha1_from_ref[20]; unsigned char *this_result; @@ -273,7 +267,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) int logs_found = 0; *log = NULL; - for (p = ref_fmt; *p; p++) { + for (p = ref_rev_parse_rules; *p; p++) { struct stat st; unsigned char hash[20]; char path[PATH_MAX]; @@ -366,7 +360,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) fprintf(stderr, "warning: Log for '%.*s' only goes " "back to %s.\n", len, str, - show_rfc2822_date(co_time, co_tz)); + show_date(co_time, co_tz, DATE_RFC2822)); else fprintf(stderr, "warning: Log for '%.*s' only has " @@ -606,24 +600,35 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) { struct commit_list *list = NULL, *backup = NULL, *l; int retval = -1; + char *temp_commit_buffer = NULL; if (prefix[0] == '!') { if (prefix[1] != '!') die ("Invalid search pattern: %s", prefix); prefix++; } - if (!save_commit_buffer) - return error("Could not expand oneline-name."); for_each_ref(handle_one_ref, &list); for (l = list; l; l = l->next) commit_list_insert(l->item, &backup); while (list) { char *p; struct commit *commit; + enum object_type type; + unsigned long size; commit = pop_most_recent_commit(&list, ONELINE_SEEN); parse_object(commit->object.sha1); - if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n"))) + if (temp_commit_buffer) + free(temp_commit_buffer); + if (commit->buffer) + p = commit->buffer; + else { + p = read_sha1_file(commit->object.sha1, &type, &size); + if (!p) + continue; + temp_commit_buffer = p; + } + if (!(p = strstr(p, "\n\n"))) continue; if (!prefixcmp(p + 2, prefix)) { hashcpy(sha1, commit->object.sha1); @@ -631,6 +636,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) break; } } + if (temp_commit_buffer) + free(temp_commit_buffer); free_commit_list(list); for (l = backup; l; l = l->next) clear_commit_marks(l->item, ONELINE_SEEN); @@ -654,7 +661,6 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode) const char *cp; *mode = S_IFINVALID; - prepare_alt_odb(); ret = get_sha1_1(name, namelen, sha1); if (!ret) return ret; @@ -679,8 +685,6 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode) namelen = namelen - (cp - name); if (!active_cache) read_cache(); - if (active_nr < 0) - return -1; pos = cache_name_pos(cp, namelen); if (pos < 0) pos = -pos - 1; @@ -691,7 +695,7 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode) break; if (ce_stage(ce) == stage) { hashcpy(sha1, ce->sha1); - *mode = ntohl(ce->ce_mode); + *mode = ce->ce_mode; return 0; } pos++;