All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Jonathan Niedier <jrnieder@gmail.com>
Cc: "Kevin Ballard" <kevin@sb.org>, "Yann Dirson" <dirson@bertin.fr>,
	"Jeff King" <peff@peff.net>, "Jakub Narebski" <jnareb@gmail.com>,
	"Thiago Farina" <tfransosi@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/3] get_sha1_oneline: let callers initialize the commit tips for traverse
Date: Mon, 13 Dec 2010 10:01:14 +0700	[thread overview]
Message-ID: <1292209275-17451-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1292209275-17451-1-git-send-email-pclouds@gmail.com>

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@gmail.com>
---
 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(&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 |= 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

  reply	other threads:[~2010-12-13  3:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13  3:01 [PATCH 1/3] get_sha1_oneline: do not leak or double free Nguyễn Thái Ngọc Duy
2010-12-13  3:01 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-13  3:01 ` [PATCH 3/3] get_sha1: support ref^{/regex} syntax Nguyễn Thái Ngọc Duy
2010-12-13  3:10   ` Nguyen Thai Ngoc Duy
2010-12-13  4:40     ` Jonathan Nieder
2010-12-15  0:50   ` Junio C Hamano
2010-12-15  1:58     ` Nguyen Thai Ngoc Duy
2010-12-15  2:56       ` Junio C Hamano
2010-12-15  3:12         ` Nguyen Thai Ngoc Duy
2010-12-15  9:02           ` [PATCH] get_sha1: handle special case $commit^{/} Nguyễn Thái Ngọc Duy
2010-12-15 23:44             ` Junio C Hamano
2010-12-16  0:23               ` Nguyen Thai Ngoc Duy
2010-12-13  6:12 ` [PATCH 1/3] get_sha1_oneline: do not leak or double free Junio C Hamano
2010-12-13  6:19   ` Junio C Hamano
2010-12-13  6:27     ` Nguyen Thai Ngoc Duy
2010-12-13  6:31     ` Junio C Hamano
2010-12-13  6:43       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1292209275-17451-2-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=dirson@bertin.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=kevin@sb.org \
    --cc=peff@peff.net \
    --cc=tfransosi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.