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

Re: [PATCH 14/14] Build in merge

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Jul 1, 2008, 12:50 UTC
Message-ID
<20080701125023.GW4729@genesis.frugalware.org>
In-Reply-To
<7vtzfaqg16.fsf@gitster.siamese.dyndns.org>
On Mon, Jun 30, 2008 at 11:23:17PM -0700, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Miklos Vajna <vmiklos@frugalware.org> writes:
> 
> > +static int read_tree_trivial(unsigned char *common, unsigned char *head,
> > +	unsigned char *one)
> > +{
> > +	int i, nr_trees = 0;
> > +	struct tree *trees[MAX_UNPACK_TREES];
> > +	struct tree_desc t[MAX_UNPACK_TREES];
> > +	struct unpack_trees_options opts;
> > +
> > +	memset(&opts, 0, sizeof(opts));
> > +	opts.head_idx = 2;
> 
> Do you still need this assignment here?
No, it was duplicated.
Show 68 quoted lines
> > +int cmd_merge(int argc, const char **argv, const char *prefix)
> > +{
> > +	unsigned char result_tree[20];
> > +	struct strbuf buf;
> > +	const char *head_arg;
> > +	int flag, head_invalid = 0, i;
> > +	int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
> > +	struct commit_list *common = NULL;
> > +	struct path_list_item *best_strategy = NULL, *wt_strategy = NULL;
> > +	struct commit_list **remotes = &remoteheads;
> > +
> > +	setup_work_tree();
> > +	if (unmerged_cache())
> > +		die("You are in the middle of a conflicted merge.");
> > +
> > +	/*
> > +	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
> > +	 * current branch.
> > +	 */
> > +	branch = resolve_ref("HEAD", head, 0, &flag);
> > +	if (branch && flag & REF_ISSYMREF) {
> > +		const char *ptr = skip_prefix(branch, "refs/heads/");
> > +		if (ptr)
> > +			branch = ptr;
> > +	} else
> > +		head_invalid = 1;
> 
> Wait a minute...  Are you calling a detached HEAD as head_invalid here?  I
> am not too much worried about variable naming, but you later do ...
> 
> > +	if (!have_message && is_old_style_invocation(argc, argv)) {
> > ...
> > +	} else if (head_invalid) {
> > +		struct object *remote_head;
> > +		/*
> > +		 * If the merged head is a valid one there is no reason
> > +		 * to forbid "git merge" into a branch yet to be born.
> > +		 * We do the same for "git pull".
> > +		 */
> > +		if (argc != 1)
> > +			die("Can merge only exactly one commit into "
> > +				"empty head");
> 
> Which is about HEAD pointing at a branch that isn't born yet.  They are
> two very different concepts.
> 
> Either the above "else if (head_invalid)" is wrong, or more likely the
> setting of head_invalid we saw earlier is wrong.
> 
> Probably what you meant was:
> 
> 	- "char *branch" points at either "HEAD" (when detached) or
>           the name of the branch (e.g. "master" when "refs/heads/master");
> 
> 	- "unsigned char head[]" stores the commit object name of the
>           current HEAD (or 0{40} if the current branch is unborn);
> 
>         - set head_invalid to true only when the current branch is unborn.
> 
> So perhaps...
> 
> 	branch = resolve_ref("HEAD", head, 0, &flag);
>         if (branch && (flag & REF_ISSYMREF) && !prefixcmp(branch, "refs/heads/"))
> 		branch += 11;
>         head_invalid = is_null_sha1(head);
> 
> And probably we can even drop (flag & REF_ISSYMREF) from the above safely.
> Do we even care if the head is detached in this program?  I doubt it.

You are right. I though we care about it, but now I realized such a comment was only in git-merge.annotated (in Dscho's fork), not in git-merge.sh. And yes, I mixed up head_invalid for two purposes. Thanks for clearing the situation.

Show 16 quoted lines
> > +		strbuf_init(&msg, 0);
> > +		strbuf_addstr(&msg, "Fast forward");
> > +		if (have_message)
> > +			strbuf_addstr(&msg,
> > +				" (no commit created; -m option ignored)");
> > +		o = peel_to_type(sha1_to_hex(remoteheads->item->object.sha1),
> > +			0, NULL, OBJ_COMMIT);
> > +		if (!o)
> > +			return 1;
> > +
> > +		if (checkout_fast_forward(head, remoteheads->item->object.sha1))
> > +			return 1;
> 
> Not exiting with 0 status from around here upon error is an improvement,
> but does the user see sensible error messages in addition to the exit
> status?
Now he/she does. :-)

(I updated my working branch on repo.or.cz, will send a patch soon, as well.)

Previous: Junio C HamanoNext: Miklos Vajna
Message 6 of 26 in “Build in merge”
  1. 00/14 Build in mergeMiklos Vajna, Jul 1, 2008
  2. 08/14 Add new test to ensure git-merge handles more than 25 refs.Miklos Vajna, Jul 1, 2008
  3. 13/14 git-commit-tree: make it usable from other builtinsMiklos Vajna, Jul 1, 2008
  4. 14/14 Build in mergeMiklos Vajna, Jul 1, 2008
  5. Junio C HamanoJul 1, 2008
  6. Miklos VajnaJul 1, 2008
  7. 14/14 Build in mergeMiklos Vajna, Jul 1, 2008
  8. Junio C HamanoJul 1, 2008
  9. Miklos VajnaJul 2, 2008
  10. Junio C HamanoJul 6, 2008
  11. Junio C HamanoJul 6, 2008
  12. Miklos VajnaJul 7, 2008
  13. Junio C HamanoJul 7, 2008
  14. Build in mergeMiklos Vajna, Jul 7, 2008
  15. Junio C HamanoJul 8, 2008
  16. Junio C HamanoJul 8, 2008
  17. Build in mergeMiklos Vajna, Jul 8, 2008
  18. Miklos VajnaJul 8, 2008
  19. Junio C HamanoJul 8, 2008
  20. Miklos VajnaJul 8, 2008
  21. Johannes SchindelinJul 6, 2008
  22. Junio C HamanoJul 6, 2008
  23. Build in mergeMiklos Vajna, Jul 7, 2008
  24. Miklos VajnaJul 7, 2008
  25. Junio C HamanoJul 1, 2008
  26. Miklos VajnaJul 1, 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.