git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] get_sha1_oneline: do not leak or double free

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 13, 2010, 06:31 UTC
Message-ID
<7voc8q5gll.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vvd2y5h63.fsf@alter.siamese.dyndns.org>
... and this is how your [2/3] would look on top of that.

I didn't change the scratchpad bit assignment in this commit, as that is a logically separate change and I didn't look at all the codepaths that can call into this function to make sure they never use TMP_MARK themselves.

They shouldn't, but it is easier to revert the change if there were.
-- >8 --
From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date: Mon, 13 Dec 2010 10:01:14 +0700
Subject: [PATCH 2/3] get_sha1_oneline: make callers prepare the commit list to traverse

This gives callers more control, i.e. which ref will be searched from. They must prepare the list ordered by committer date.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 sha1_name.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 2cc7a42..aefae1f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -686,13 +686,13 @@ 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 *backup = NULL, *l;
 	int found = 0;
 	regex_t regex;
 
@@ -705,9 +705,10 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 	if (regcomp(&regex, 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 |= ONELINE_SEEN;
 		commit_list_insert(l->item, &backup);
+	}
 	while (list) {
 		char *p, *to_free = NULL;
 		struct commit *commit;
@@ -1090,9 +1091,11 @@ 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] == '/')
-			/* don't need mode for commit */
-			return get_sha1_oneline(name + 2, sha1);
+		if (namelen > 2 && name[1] == '/') {
+			struct commit_list *list = NULL;
+			for_each_ref(handle_one_ref, &list);
+			return get_sha1_oneline(name + 2, sha1, list);
+		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
 		    name[1] < '0' || '3' < name[1])
Previous: Nguyen Thai Ngoc DuyNext: Junio C Hamano
Message 16 of 17 in “get_sha1_oneline: do not leak or double free”
  1. 1/3 get_sha1_oneline: do not leak or double freeNguyễn Thái Ngọc Duy, Dec 13, 2010
  2. 2/3 get_sha1_oneline: let callers initialize the commit tips for traverseNguyễn Thái Ngọc Duy, Dec 13, 2010
  3. 3/3 get_sha1: support ref^{/regex} syntaxNguyễn Thái Ngọc Duy, Dec 13, 2010
  4. Nguyen Thai Ngoc DuyDec 13, 2010
  5. Jonathan NiederDec 13, 2010
  6. Junio C HamanoDec 15, 2010
  7. Nguyen Thai Ngoc DuyDec 15, 2010
  8. Junio C HamanoDec 15, 2010
  9. Nguyen Thai Ngoc DuyDec 15, 2010
  10. get_sha1: handle special case $commit^{/}Nguyễn Thái Ngọc Duy, Dec 15, 2010
  11. Junio C HamanoDec 15, 2010
  12. Nguyen Thai Ngoc DuyDec 16, 2010
  13. Junio C HamanoDec 13, 2010
  14. Junio C HamanoDec 13, 2010
  15. Nguyen Thai Ngoc DuyDec 13, 2010
  16. Junio C HamanoDec 13, 2010
  17. Junio C HamanoDec 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.