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

Re: [PATCH v3] git-branch: add support for --merged and --no-merged

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 17, 2008, 21:07 UTC
Message-ID
<7vzlrsmbqw.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1208463890-2870-1-git-send-email-hjemli@gmail.com>
Lars Hjemli <hjemli@gmail.com> writes:
Show 7 quoted lines
> Junio C Hamano wrote:
>> If the existing --contains implemenation can be extended to allow negative
>> selection, we do not have to introduce yet another mechanism that is very
>> similar.
>
> Very true, so here's an updated version which reuses has_commit(). Thanks
> for the feedback.
Show 9 quoted lines
> +	if (mergefilter > -1) {
> +		branch.item = lookup_commit_reference_gently(sha1, 1);
> +		if (!branch.item)
> +			die("Unable to lookup HEAD of branch %s", refname);
> +		if (mergefilter == 0 && has_commit(head_sha1, &branch))
> +			return 0;
> +		if (mergefilter == 1 && !has_commit(head_sha1, &branch))
> +			return 0;
> +	}

You did not answer my question as to how --contains and --merged relate to each other. I'll answer it myself (please add a documentation updates, as this would be confusing). The output from the former is "branches I need to be careful about, if I were to rewind and rebuild this branch" (that is what I invented the option for). The output from the latter is "branches I can remove with 'git branch -d'".

 * --contains (aka with_commit) gets a single commit; only the branches
   that are descendant of that named commit will be shown (iow, these
   branches contain the commit), with the expression:
	/* Filter with with_commit if specified */
	if (!has_commit(sha1, ref_list->with_commit))
		return 0;
   where "sha1" is the commit at the tip of the branch in question in this
   round of the loop.
 * --merged is the opposite way.  Only the branches whose tips are
   ancestors of the HEAD will be shown (iow, the HEAD contains these
   branches), with the expression:
   	if (has_commit(head_sha1, &branch))
   where "head_sha1" is the HEAD, and "branch" is the branch in question
   in this round of the loop.  i.e. it asks the same question as
   --contains but in the opposite way.
Previous: Lars HjemliNext: Lars Hjemli
Message 6 of 8 in “git-branch: add support for --merged and --unmerged”
  1. git-branch: add support for --merged and --unmergedLars Hjemli, Apr 17, 2008
  2. bash: support branch's new '--merged' and '--unmerged' optionsSZEDER Gábor, Apr 17, 2008
  3. git-branch: add support for --merged and --no-mergedLars Hjemli, Apr 17, 2008
  4. Junio C HamanoApr 17, 2008
  5. git-branch: add support for --merged and --no-mergedLars Hjemli, Apr 17, 2008
  6. Junio C HamanoApr 17, 2008
  7. git-branch.txt: compare --contains, --merged and --no-mergedLars Hjemli, Apr 17, 2008
  8. Lars HjemliApr 17, 2008

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.