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

Re: [JGIT PATCH 8/8] Define a basic merge API, and a two-way tree merge strategy

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 19, 2009, 17:42 UTC
Message-ID
<20090119174254.GC14053@spearce.org>
In-Reply-To
<f299b4f30901171116y216835c9jc11df2d424ee0377@mail.gmail.com>
Tomi Pakarinen <tomi.pakarinen@gmail.com> wrote:
> testTrivialTwoWay_disjointhistories() failed because merge strategy
> didn't handle missing base
> version. Am'i right?
I don't think so.
 
> @@ -119,13 +120,26 @@ protected boolean mergeImpl() throws IOException {
>  				}
> 
>  				final int modeB = tw.getRawMode(T_BASE);
Under a missing base condition modeB == 0.  So,
> -				if (modeB == modeO && tw.idEqual(T_BASE, T_OURS))
> -					add(T_THEIRS, DirCacheEntry.STAGE_0);

If modeB == 0 and modeO == 0 its not in the base and its not in ours. Both SHA-1s will be 0{40} and are thus idEqual, so we should enter this add(T_THEIRS) block. Which is what you tried to write below in your else block, isn't it?.

> -				else if (modeB == modeT && tw.idEqual(T_BASE, T_THEIRS))
> -					add(T_OURS, DirCacheEntry.STAGE_0);

Again, if modeB == 0 and modeT == 0 both SHA-1s will be 0{40} and are idEqual, so we should enter this add(T_OURS) block if both base and theirs are missing. Which again is what you tried to write in your else block.

If that isn't coming out right then perhaps tw.idEqual() is busted for when FileMode is FileMode.MISSING (aka 0). Granted, doing idEqual on FileMode.MISSING is pointless and just wastes clock cycles, but it shouldn't harm the algorithm's correctness.

Show 28 quoted lines
> -				else {
> -					conflict();
> -					hasConflict = true;
> +				if (!FileMode.MISSING.equals(modeB)) {
> +					if (modeB == modeO && tw.idEqual(T_BASE, T_OURS))
> +						add(T_THEIRS, DirCacheEntry.STAGE_0);
> +					else if (modeB == modeT && tw.idEqual(T_BASE, T_THEIRS))
> +						add(T_OURS, DirCacheEntry.STAGE_0);
> +					else {
> +						conflict();
> +						hasConflict = true;
> +					}
> +				} else {
> +					if (!FileMode.MISSING.equals(modeO)
> +							&& FileMode.MISSING.equals(modeT))
> +						add(T_OURS, DirCacheEntry.STAGE_0);
> +					else if (FileMode.MISSING.equals(modeO)
> +							&& !FileMode.MISSING.equals(modeT))
> +						add(T_THEIRS, DirCacheEntry.STAGE_0);
> +					else {
> +						conflict();
> +						hasConflict = true;
> +					}
>  				}
>  			}
>  			builder.finish();
> -- 
> 1.6.0.4
-- 
Shawn.
Previous: Robin RosenbergNext: Shawn O. Pearce
Message 15 of 16 in “Crude merge support”
  1. 0/8 Crude merge supportShawn O. Pearce, Oct 13, 2008
  2. 1/8 Expose the raw path for the current entry of a TreeWalkShawn O. Pearce, Oct 13, 2008
  3. 2/8 Expose DirCacheEntry.getFileMode as a utility functionShawn O. Pearce, Oct 13, 2008
  4. 3/8 Add writeTree support to DirCacheShawn O. Pearce, Oct 13, 2008
  5. 4/8 Allow a DirCache to be created with no backing store fileShawn O. Pearce, Oct 13, 2008
  6. 5/8 Allow CanonicalTreeParsers to be created with a UTF-8 path prefixShawn O. Pearce, Oct 13, 2008
  7. 6/8 Recursively load an entire tree into a DirCacheBuilderShawn O. Pearce, Oct 13, 2008
  8. 7/8 Allow DirCacheEntry instances to be created with stage > 0Shawn O. Pearce, Oct 13, 2008
  9. 8/8 Define a basic merge API, and a two-way tree merge strategyShawn O. Pearce, Oct 13, 2008
  10. Robin RosenbergOct 23, 2008
  11. Robin RosenbergJan 15, 2009
  12. Shawn O. PearceJan 15, 2009
  13. Tomi PakarinenJan 17, 2009
  14. Robin RosenbergJan 18, 2009
  15. Shawn O. PearceJan 19, 2009
  16. Shawn O. PearceJan 19, 2009

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.