Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx> --- sha1_name.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 2c3a5fb..f4ccdc5 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -686,13 +686,14 @@ static int handle_one_ref(const char *path, 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 *list = list_, *backup = NULL, *l; int retval = -1; char *temp_commit_buffer = NULL; regex_t regex; @@ -706,9 +707,12 @@ 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) + if (!list) + for_each_ref(handle_one_ref, &list); + for (l = list; l; l = l->next) { commit_list_insert(l->item, &backup); + l->item->object.flags |= ONELINE_SEEN; + } while (list) { char *p; struct commit *commit; @@ -737,7 +741,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) } regfree(®ex); free(temp_commit_buffer); - free_commit_list(list); + if (!list_) + free_commit_list(list); for (l = backup; l; l = l->next) clear_commit_marks(l->item, ONELINE_SEEN); return retval; @@ -1090,7 +1095,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1, int pos; if (namelen > 2 && name[1] == '/') /* don't need mode for commit */ - return get_sha1_oneline(name + 2, sha1); + return get_sha1_oneline(name + 2, sha1, NULL); if (namelen < 3 || name[2] != ':' || name[1] < '0' || '3' < name[1]) -- 1.7.3.2.316.gda8b3 -- 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