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

Re: [PATCH v1 1/4] make rewrite_parents an external function

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 14, 2010, 19:10 UTC
Message-ID
<7vpqypyj43.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1278829657-26607-2-git-send-email-struggleyb.nku@gmail.com>
Bo Yang <struggleyb.nku@gmail.com> writes:
Show 8 quoted lines
> The function rewrite_one is used to rewrite a single
> parent of the current commit, and is used by rewrite_parents
> to rewrite all the parents.
> This commit decouple the dependence between them, make
> rewrite_one as a callback function and be passed to
> rewrite_parents. Make rewrite_parents public to other
> part of git.
> We will use this function in line.c.
Sorry, but -ECANTREALLYPARSE.

This particular refactoring is probably harmless, but we would need to see how it is used to convince ourselves it is a good change.

Show 19 quoted lines
> @@ -1920,7 +1914,8 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
>  	}
>  }
>  
> -static int rewrite_parents(struct rev_info *revs, struct commit *commit)
> +int rewrite_parents(struct rev_info *revs, struct commit *commit,
> +	rewrite_parent rewrite_one)
>  {
>  	struct commit_list **pp = &commit->parents;
>  	while (*pp) {
> @@ -1993,7 +1988,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
>  	if (action == commit_show &&
>  	    !revs->show_all &&
>  	    revs->prune && revs->dense && want_ancestry(revs)) {
> -		if (rewrite_parents(revs, commit) < 0)
> +		if (rewrite_parents(revs, commit, rewrite_one) < 0)
>  			return commit_error;
>  	}
>  	return action;

It would probably make sense to rename this "rewrite_one" (local function pointer variable) not to collide with the "rewrite_one" (static function) for readability.

Show 15 quoted lines
> diff --git a/revision.h b/revision.h
> index 433da9a..9b8e3d9 100644
> --- a/revision.h
> +++ b/revision.h
> @@ -200,4 +200,14 @@ enum commit_action {
>  extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
>  extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
>  
> +enum rewrite_result {
> +	rewrite_one_ok,
> +	rewrite_one_noparents,
> +	rewrite_one_error
> +};
> +
> +typedef enum rewrite_result (*rewrite_parent)(struct rev_info *revs, struct commit **pp);
Yikes; at least name the type rewrite_parent_fn or something for readability.
Show 5 quoted lines
> +extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
> +	rewrite_parent rewrite_one);
>  #endif
> -- 
> 1.7.0.2.273.gc2413.dirty
Previous: Bo YangNext: Bo Yang
Message 3 of 8 in “add parent rewrite feature to line level log”
  1. 0/4 add parent rewrite feature to line level logBo Yang, Jul 11, 2010
  2. 1/4 make rewrite_parents an external functionBo Yang, Jul 11, 2010
  3. Junio C HamanoJul 14, 2010
  4. 2/4 add parent rewrite feature to line level logBo Yang, Jul 11, 2010
  5. Junio C HamanoJul 13, 2010
  6. 3/4 line.c output the '--graph' padding before each lineBo Yang, Jul 11, 2010
  7. Junio C HamanoJul 13, 2010
  8. 4/4 add test cases for '--graph' of line level logBo Yang, Jul 11, 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.