git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Kevin Ballard <kevin@sb.org>,
	Yann Dirson <dirson@bertin.fr>, Jeff King <peff@peff.net>,
	Jakub Narebski <jnareb@gmail.com>,
	Jonathan Niedier <jrnieder@gmail.com>,
	Thiago Farina <tfransosi@gmail.com>
Subject: Re: [PATCH 1/2] get_sha1_oneline: allow to input commit_list
Date: Sun, 12 Dec 2010 16:29:06 -0800	[thread overview]
Message-ID: <7vsjy27bxp.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1292151419-30678-1-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Sun\, 12 Dec 2010 17\:56\:58 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  sha1_name.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index 2c3a5fb..c298285 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -690,7 +690,9 @@ static int handle_one_ref(const char *path,
>  	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 *original_list)
>  {
>  	struct commit_list *list = NULL, *backup = NULL, *l;
>  	int retval = -1;
> @@ -706,7 +708,12 @@ 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 = original_list; l; l = l->next) {
> +		commit_list_insert(l->item, &list);
> +		l->item->object.flags |= ONELINE_SEEN;
> +	}
> +	if (!list)
> +		for_each_ref(handle_one_ref, &list);

Two-and-half yucks.

 (1) "We work on the list you give us, if you give us one, but we work on
     a list we come up with outselves in a magic way otherwise" is an API
     designed with a bad taste.  Why not make the original caller run
     for-each-ref before calling this function?

 (2) Why do you have to copy the list, using commit-list-insert, here?

 (3) Even if the above extra copy turns out to be needed, do you need yet
     another copy in "backup"?

Instead of this patch, I would suggest to go this route:

 * Remove local varaible "list" and make it an input parameter.

 * Stop calling for-each-ref from this function.  Instead, have the
   current caller run for-each-ref to prepare list and feed it to you;

 * Stop marking commits with "ONELINE_SEEN" from handle-one-ref.  Instead,
   have the loop to copy list to backup do the marking.

That way, you make the purpose of the function much more clear.  It gets a
list of one or more commits that are in date-order, and finds the most
recent commit reachable from them that match the given string, using
ONELINE_SEEN bit as a scratchpad (shouldn't we be using TMP_MARK here, by
the way?).  The caller is responsible for giving you a sorted list, but
the caller shouldn't care about ONELINE_SEEN bit.

  parent reply	other threads:[~2010-12-13  0:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-12 10:56 [PATCH 1/2] get_sha1_oneline: allow to input commit_list Nguyễn Thái Ngọc Duy
2010-12-12 10:56 ` [PATCH 2/2] get_sha1: support ref^{/regex} syntax Nguyễn Thái Ngọc Duy
2010-12-12 17:38   ` Jonathan Nieder
2010-12-12 17:34 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Jonathan Nieder
2010-12-13  0:29 ` Junio C Hamano [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-12-08 14:58 [PATCH 0/2] [RFD] Using gitrevisions :/search style with other operators Nguyễn Thái Ngọc Duy
2010-12-08 14:58 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Nguyễn Thái Ngọc Duy
2010-12-08 15:11   ` Thiago Farina

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7vsjy27bxp.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=dirson@bertin.fr \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=kevin@sb.org \
    --cc=pclouds@gmail.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).