This gives callers more control, i.e. which ref will be searched from. get_sha1_oneline takes care of ONELINE_SEEN marks (which is now TMP_MARK) Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx> --- sha1_name.c | 62 +++++++++++++++++++++++++++++++--------------------------- 1 files changed, 33 insertions(+), 29 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 13ee6f5..3c2c61c 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -6,6 +6,8 @@ #include "tree-walk.h" #include "refs.h" #include "remote.h" +#include "diff.h" +#include "revision.h" static int find_short_object_filename(int len, const char *name, unsigned char *sha1) { @@ -669,30 +671,10 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1) * For future extension, ':/!' is reserved. If you want to match a message * beginning with a '!', you have to repeat the exclamation mark. */ -#define ONELINE_SEEN (1u<<20) - -static int handle_one_ref(const char *path, - const unsigned char *sha1, int flag, void *cb_data) -{ - struct commit_list **list = cb_data; - struct object *object = parse_object(sha1); - if (!object) - return 0; - if (object->type == OBJ_TAG) { - object = deref_tag(object, path, strlen(path)); - if (!object) - return 0; - } - if (object->type != OBJ_COMMIT) - return 0; - insert_by_date((struct commit *)object, list); - object->flags |= ONELINE_SEEN; - return 0; -} - -static int get_sha1_oneline(const char *prefix, unsigned char *sha1) +static int get_sha1_oneline(const char *prefix, unsigned char *sha1, + struct commit_list *list) { - struct commit_list *list = NULL, *backup = NULL, *l; + struct commit_list *backup = NULL, *l; int retval = -1; char *temp_commit_buffer = NULL; regex_t regex; @@ -706,16 +688,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) if (regcomp(®ex, prefix, REG_EXTENDED)) die("Invalid search pattern: %s", prefix); - for_each_ref(handle_one_ref, &list); - for (l = list; l; l = l->next) + for (l = list; l; l = l->next) { + l->item->object.flags |= TMP_MARK; 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); + commit = pop_most_recent_commit(&list, TMP_MARK); if (!parse_object(commit->object.sha1)) continue; if (commit->buffer) @@ -739,7 +722,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) free(temp_commit_buffer); free_commit_list(list); for (l = backup; l; l = l->next) - clear_commit_marks(l->item, ONELINE_SEEN); + clear_commit_marks(l->item, TMP_MARK); free_commit_list(backup); return retval; } @@ -1067,6 +1050,24 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, return ret; } +static int handle_one_ref(const char *path, + const unsigned char *sha1, int flag, void *cb_data) +{ + struct commit_list **list = cb_data; + struct object *object = parse_object(sha1); + if (!object) + return 0; + if (object->type == OBJ_TAG) { + object = deref_tag(object, path, strlen(path)); + if (!object) + return 0; + } + if (object->type != OBJ_COMMIT) + return 0; + insert_by_date((struct commit *)object, list); + return 0; +} + int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *oc, int gently, const char *prefix) @@ -1089,9 +1090,12 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1, int stage = 0; struct cache_entry *ce; int pos; - if (namelen > 2 && name[1] == '/') + if (namelen > 2 && name[1] == '/') { + struct commit_list *list = NULL; + for_each_ref(handle_one_ref, &list); /* don't need mode for commit */ - return get_sha1_oneline(name + 2, sha1); + return get_sha1_oneline(name + 2, sha1, list); + } if (namelen < 3 || name[2] != ':' || name[1] < '0' || '3' < name[1]) -- 1.7.3.3.476.g10a82 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html