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

Re: [PATCH v5 2/4] format-patch: add '--base' option to record base tree info

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 22, 2016, 21:52 UTC
Message-ID
<xmqqoa91nwf9.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1461303756-25975-3-git-send-email-xiaolong.ye@intel.com>
Xiaolong Ye <xiaolong.ye@intel.com> writes:
Show 30 quoted lines
> +static struct commit *get_base_commit(const char *base_commit,
> +				      struct commit **list,
> +				      int total)
> +{
> +	struct commit *base = NULL;
> +	struct commit **rev;
> +	int i = 0, rev_nr = 0;
> +
> +	base = lookup_commit_reference_by_name(base_commit);
> +	if (!base)
> +		die(_("Unknown commit %s"), base_commit);
> +
> +	ALLOC_ARRAY(rev, total);
> +	for (i = 0; i < total; i++)
> +		rev[i] = list[i];
> +
> +	rev_nr = total;
> +	/*
> +	 * Get merge base through pair-wise computations
> +	 * and store it in rev[0].
> +	 */
> +	while (rev_nr > 1) {
> +		for (i = 0; i < rev_nr / 2; i++) {
> +			struct commit_list *merge_base;
> +			merge_base = get_merge_bases(rev[2 * i], rev[2 * i + 1]);
> +			if (!merge_base || merge_base->next)
> +				die(_("Failed to find exact merge base"));
> +
> +			rev[i] = merge_base->item;
> +		}

So merge-base(0,1) is stored in rev[0], merge-base(2,3) is then stored in rev[1], etc. and the last item, if rev_nr is odd, is left in rev[rev_nr-1]. When the loop finishes, i is left as rev_nr/2 and...

> +		if (rev_nr % 2)
> +			rev[i] = rev[2 * i];

... when rev_nr is odd, that left-over thing moved down here. E.g. if rev_nr == 5, the loop is left with i==2, rev[0] and rev[1] are filled with pairwise merge bases, and this moves rev[4] to rev[2], so that we can further process rev[0,1,2] with rev_nr set to 3 (i.e. (rev_nr + 1) / 2 below).

Sounds correct.
Show 14 quoted lines
> +		rev_nr = (rev_nr + 1) / 2;
> +	}
> +
> +	if (!in_merge_bases(base, rev[0]))
> +		die(_("base commit should be the ancestor of revision list"));
> +
> +	for (i = 0; i < total; i++) {
> +		if (base == list[i])
> +			die(_("base commit shouldn't be in revision list"));
> +	}
> +
> +	free(rev);
> +	return base;
> +}
Previous: Ye XiaolongNext: Junio C Hamano
Message 6 of 12 in “Add --base option to git-format-patch to record base tree info”
  1. 0/4 Add --base option to git-format-patch to record base tree infoXiaolong Ye, Apr 22, 2016
  2. 1/4 patch-ids: make commit_patch_id() a public helper functionXiaolong Ye, Apr 22, 2016
  3. 2/4 format-patch: add '--base' option to record base tree infoXiaolong Ye, Apr 22, 2016
  4. Junio C HamanoApr 22, 2016
  5. Ye XiaolongApr 24, 2016
  6. Junio C HamanoApr 22, 2016
  7. Junio C HamanoApr 22, 2016
  8. Ye XiaolongApr 24, 2016
  9. 3/4 format-patch: introduce --base=auto optionXiaolong Ye, Apr 22, 2016
  10. Junio C HamanoApr 22, 2016
  11. Ye XiaolongApr 24, 2016
  12. 4/4 format-patch: introduce format.useAutoBase configurationXiaolong Ye, Apr 22, 2016

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.