{"thread":{"id":"17310","subject":"[JGIT PATCH 00/10] Merge API v2","startedAt":"2009-01-22T23:28:00Z","lastAt":"2009-01-23T21:42:14Z","messageCount":12,"participants":["Shawn O. Pearce","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":10},"messages":[{"id":"101567","messageId":"1232666890-23488-1-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":null,"subject":"[JGIT PATCH 00/10] Merge API v2","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:00Z","receivedAt":"2009-01-22T23:28:00Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"2nd attempt at the merge API.  Changes from my prior posting last fall:\n\n - Fixed the bug Robin identified (the first patch in the series)\n - Rebased against current master\n - Basic smoke tests provided by Robin\n\nShawn O. Pearce (10):\n  Fix TreeWalk.idEqual when both trees are missing the path\n  Expose the raw path for the current entry of a TreeWalk\n  Expose DirCacheEntry.getFileMode as a utility function\n  Add writeTree support to DirCache\n  Allow a DirCache to be created with no backing store file\n  Allow CanonicalTreeParsers to be created with a UTF-8 path prefix\n  Recursively load an entire tree into a DirCacheBuilder\n  Allow DirCacheEntry instances to be created with stage > 0\n  Define a basic merge API, and a two-way tree merge strategy\n  Add a few simple merge test cases\n\n .../spearce/jgit/test/resources/create-second-pack |   13 +-\n ...ck-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx |  Bin 0 -> 1296 bytes\n ...k-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack |  Bin 0 -> 562 bytes\n ...ck-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx |  Bin 1088 -> 1100 bytes\n ...ck-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx |  Bin 2696 -> 2976 bytes\n ...k-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack |  Bin 5956 -> 5901 bytes\n .../org/spearce/jgit/test/resources/packed-refs    |    4 +-\n .../org/spearce/jgit/lib/RepositoryTestCase.java   |    3 +-\n .../org/spearce/jgit/merge/SimpleMergeTest.java    |   86 ++++++++\n .../org/spearce/jgit/transport/TransportTest.java  |    2 +-\n .../src/org/spearce/jgit/dircache/DirCache.java    |   37 ++++\n .../org/spearce/jgit/dircache/DirCacheBuilder.java |   65 ++++++\n .../org/spearce/jgit/dircache/DirCacheEntry.java   |   61 +++++-\n .../org/spearce/jgit/dircache/DirCacheTree.java    |  115 +++++++++++\n .../spearce/jgit/errors/UnmergedPathException.java |   67 ++++++\n .../src/org/spearce/jgit/lib/FileMode.java         |    7 +\n .../src/org/spearce/jgit/lib/ObjectWriter.java     |   12 +-\n .../src/org/spearce/jgit/merge/MergeStrategy.java  |  134 ++++++++++++\n .../src/org/spearce/jgit/merge/Merger.java         |  213 ++++++++++++++++++++\n .../org/spearce/jgit/merge/StrategyOneSided.java   |   98 +++++++++\n .../jgit/merge/StrategySimpleTwoWayInCore.java     |  179 ++++++++++++++++\n .../jgit/treewalk/AbstractTreeIterator.java        |   31 +++\n .../spearce/jgit/treewalk/CanonicalTreeParser.java |   30 +++\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   28 +++-\n 24 files changed, 1170 insertions(+), 15 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx\n create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java\n"},{"id":"101570","messageId":"1232666890-23488-2-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 01/10] Fix TreeWalk.idEqual when both trees are missing the path","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:01Z","receivedAt":"2009-01-22T23:28:01Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The Javadoc of idEqual() says its simply a faster form of\ngetObjectId(nthA).equals(getObjectId(nthB)), but its code\ndidn't match that definition when both trees didn't exist\nat the current path.\n\nIf a tree doesn't exist for the current path getObjectId() returns\nObjectId.zero(), indicating the \"magic\" 0{40} SHA-1 for the current\npath.  If both tree entries don't exist for the current path, we\nshould be doing a compare of ObjectId.zero() against ObjectId.zero(),\nwhich must be true as the values are the same.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   11 ++++++++++-\n 1 files changed, 10 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex ecf8851..414587c 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -616,7 +616,16 @@ public boolean idEqual(final int nthA, final int nthB) {\n \t\tfinal AbstractTreeIterator ch = currentHead;\n \t\tfinal AbstractTreeIterator a = trees[nthA];\n \t\tfinal AbstractTreeIterator b = trees[nthB];\n-\t\treturn a.matches == ch && b.matches == ch && a.idEqual(b);\n+\t\tif (a.matches == ch && b.matches == ch)\n+\t\t\treturn a.idEqual(b);\n+\t\tif (a.matches != ch && b.matches != ch) {\n+\t\t\t// If neither tree matches the current path node then neither\n+\t\t\t// tree has this entry. In such case the ObjectId is zero(),\n+\t\t\t// and zero() is always equal to zero().\n+\t\t\t//\n+\t\t\treturn true;\n+\t\t}\n+\t\treturn false;\n \t}\n \n \t/**\n-- \n1.6.1.399.g0d272\n"},{"id":"101569","messageId":"1232666890-23488-3-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-2-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 02/10] Expose the raw path for the current entry of a TreeWalk","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:02Z","receivedAt":"2009-01-22T23:28:02Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Copying the path byte array (keeping it encoded in UTF-8) is quicker\nthan converting to String and then back again to UTF-8 when creating\na DirCacheEntry for the current position in a TreeWalk.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   15 +++++++++++++++\n 1 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex 414587c..22040e3 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -663,6 +663,21 @@ public String getPathString() {\n \t}\n \n \t/**\n+\t * Get the current entry's complete path as a UTF-8 byte array.\n+\t * \n+\t * @return complete path of the current entry, from the root of the\n+\t *         repository. If the current entry is in a subtree there will be at\n+\t *         least one '/' in the returned string.\n+\t */\n+\tpublic byte[] getRawPath() {\n+\t\tfinal AbstractTreeIterator t = currentHead;\n+\t\tfinal int n = t.pathLen;\n+\t\tfinal byte[] r = new byte[n];\n+\t\tSystem.arraycopy(t.path, 0, r, 0, n);\n+\t\treturn r;\n+\t}\n+\n+\t/**\n \t * Test if the supplied path matches the current entry's path.\n \t * <p>\n \t * This method tests that the supplied path is exactly equal to the current\n-- \n1.6.1.399.g0d272\n"},{"id":"101568","messageId":"1232666890-23488-4-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-3-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 03/10] Expose DirCacheEntry.getFileMode as a utility function","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:03Z","receivedAt":"2009-01-22T23:28:03Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Its easier to get the FileMode object in some applications than to\nget the raw mode and convert it to the FileMode in the application\ncode.  Its slower, but sometimes you just have to have the proper\nFileMode singleton.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/dircache/DirCacheEntry.java   |    9 +++++++++\n 1 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\nindex cc683d7..355cd3e 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\n@@ -295,6 +295,15 @@ public int getRawMode() {\n \t}\n \n \t/**\n+\t * Obtain the {@link FileMode} for this entry.\n+\t * \n+\t * @return the file mode singleton for this entry.\n+\t */\n+\tpublic FileMode getFileMode() {\n+\t\treturn FileMode.fromBits(getRawMode());\n+\t}\n+\n+\t/**\n \t * Set the file mode for this entry.\n \t *\n \t * @param mode\n-- \n1.6.1.399.g0d272\n"},{"id":"101571","messageId":"1232666890-23488-5-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-4-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 04/10] Add writeTree support to DirCache","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:04Z","receivedAt":"2009-01-22T23:28:04Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This way we can write a full tree from the DirCache, including reusing\nany valid tree entries stored within the 'TREE' cache extension.  By\nreusing those entries we can avoid generating the tree objects that\nare already stored in the Git repository.\n\nThe algorithm may cause up to 3 passes over the DirCache entries:\n\n * Pass 1: Compute the tree structure\n * Pass 2: Compute the sizes of each tree\n * Pass 3: Write the tree object to the object store\n\nThese extra passes cause more CPU time to be expended in exchange\nfor a lower memory requirement during the tree writing.  The code\nis only formatting the lowest level leaf tree which has not yet\nbeen written to the object store, so higher level trees do not\noccupy memory while they are waiting for the leaves to write out.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/dircache/DirCache.java    |   20 ++++\n .../org/spearce/jgit/dircache/DirCacheTree.java    |  115 ++++++++++++++++++++\n .../spearce/jgit/errors/UnmergedPathException.java |   67 ++++++++++++\n .../src/org/spearce/jgit/lib/FileMode.java         |    7 ++\n .../src/org/spearce/jgit/lib/ObjectWriter.java     |   12 ++-\n 5 files changed, 219 insertions(+), 2 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\nindex 76657c4..b3c57ad 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n@@ -51,8 +51,11 @@\n import java.util.Comparator;\n \n import org.spearce.jgit.errors.CorruptObjectException;\n+import org.spearce.jgit.errors.UnmergedPathException;\n import org.spearce.jgit.lib.Constants;\n import org.spearce.jgit.lib.LockFile;\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.ObjectWriter;\n import org.spearce.jgit.lib.Repository;\n import org.spearce.jgit.util.MutableInteger;\n import org.spearce.jgit.util.NB;\n@@ -692,4 +695,21 @@ public DirCacheTree getCacheTree(final boolean build) {\n \t\t}\n \t\treturn tree;\n \t}\n+\n+\t/**\n+\t * Write all index trees to the object store, returning the root tree.\n+\t * \n+\t * @param ow\n+\t *            the writer to use when serializing to the store.\n+\t * @return identity for the root tree.\n+\t * @throws UnmergedPathException\n+\t *             one or more paths contain higher-order stages (stage > 0),\n+\t *             which cannot be stored in a tree object.\n+\t * @throws IOException\n+\t *             an unexpected error occurred writing to the object store.\n+\t */\n+\tpublic ObjectId writeTree(final ObjectWriter ow)\n+\t\t\tthrows UnmergedPathException, IOException {\n+\t\treturn getCacheTree(true).writeTree(sortedEntries, 0, 0, ow);\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\nindex 26b6348..cf96ded 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java\n@@ -1,5 +1,6 @@\n /*\n  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>\n+ * Copyright (C) 2008, Google Inc.\n  *\n  * All rights reserved.\n  *\n@@ -37,14 +38,20 @@\n \n package org.spearce.jgit.dircache;\n \n+import static org.spearce.jgit.lib.Constants.OBJECT_ID_LENGTH;\n+\n+import java.io.ByteArrayOutputStream;\n import java.io.IOException;\n import java.io.OutputStream;\n import java.nio.ByteBuffer;\n import java.util.Arrays;\n import java.util.Comparator;\n \n+import org.spearce.jgit.errors.UnmergedPathException;\n import org.spearce.jgit.lib.Constants;\n+import org.spearce.jgit.lib.FileMode;\n import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.ObjectWriter;\n import org.spearce.jgit.util.MutableInteger;\n import org.spearce.jgit.util.RawParseUtils;\n \n@@ -273,6 +280,114 @@ public String getPathString() {\n \t\treturn r.toString();\n \t}\n \n+\t/**\n+\t * Write (if necessary) this tree to the object store.\n+\t * \n+\t * @param cache\n+\t *            the complete cache from DirCache.\n+\t * @param cIdx\n+\t *            first position of <code>cache</code> that is a member of this\n+\t *            tree. The path of <code>cache[cacheIdx].path</code> for the\n+\t *            range <code>[0,pathOff-1)</code> matches the complete path of\n+\t *            this tree, from the root of the repository.\n+\t * @param pathOffset\n+\t *            number of bytes of <code>cache[cacheIdx].path</code> that\n+\t *            matches this tree's path. The value at array position\n+\t *            <code>cache[cacheIdx].path[pathOff-1]</code> is always '/' if\n+\t *            <code>pathOff</code> is > 0.\n+\t * @param ow\n+\t *            the writer to use when serializing to the store.\n+\t * @return identity of this tree.\n+\t * @throws UnmergedPathException\n+\t *             one or more paths contain higher-order stages (stage > 0),\n+\t *             which cannot be stored in a tree object.\n+\t * @throws IOException\n+\t *             an unexpected error occurred writing to the object store.\n+\t */\n+\tObjectId writeTree(final DirCacheEntry[] cache, int cIdx,\n+\t\t\tfinal int pathOffset, final ObjectWriter ow)\n+\t\t\tthrows UnmergedPathException, IOException {\n+\t\tif (id == null) {\n+\t\t\tfinal int endIdx = cIdx + entrySpan;\n+\t\t\tfinal int size = computeSize(cache, cIdx, pathOffset, ow);\n+\t\t\tfinal ByteArrayOutputStream out = new ByteArrayOutputStream(size);\n+\t\t\tint childIdx = 0;\n+\t\t\tint entryIdx = cIdx;\n+\n+\t\t\twhile (entryIdx < endIdx) {\n+\t\t\t\tfinal DirCacheEntry e = cache[entryIdx];\n+\t\t\t\tfinal byte[] ep = e.path;\n+\t\t\t\tif (childIdx < childCnt) {\n+\t\t\t\t\tfinal DirCacheTree st = children[childIdx];\n+\t\t\t\t\tif (st.contains(ep, pathOffset, ep.length)) {\n+\t\t\t\t\t\tFileMode.TREE.copyTo(out);\n+\t\t\t\t\t\tout.write(' ');\n+\t\t\t\t\t\tout.write(st.encodedName);\n+\t\t\t\t\t\tout.write(0);\n+\t\t\t\t\t\tst.id.copyRawTo(out);\n+\n+\t\t\t\t\t\tentryIdx += st.entrySpan;\n+\t\t\t\t\t\tchildIdx++;\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\t\t\t\te.getFileMode().copyTo(out);\n+\t\t\t\tout.write(' ');\n+\t\t\t\tout.write(ep, pathOffset, ep.length - pathOffset);\n+\t\t\t\tout.write(0);\n+\t\t\t\tout.write(e.idBuffer(), e.idOffset(), OBJECT_ID_LENGTH);\n+\t\t\t\tentryIdx++;\n+\t\t\t}\n+\n+\t\t\tid = ow.writeCanonicalTree(out.toByteArray());\n+\t\t}\n+\t\treturn id;\n+\t}\n+\n+\tprivate int computeSize(final DirCacheEntry[] cache, int cIdx,\n+\t\t\tfinal int pathOffset, final ObjectWriter ow)\n+\t\t\tthrows UnmergedPathException, IOException {\n+\t\tfinal int endIdx = cIdx + entrySpan;\n+\t\tint childIdx = 0;\n+\t\tint entryIdx = cIdx;\n+\t\tint size = 0;\n+\n+\t\twhile (entryIdx < endIdx) {\n+\t\t\tfinal DirCacheEntry e = cache[entryIdx];\n+\t\t\tif (e.getStage() != 0)\n+\t\t\t\tthrow new UnmergedPathException(e);\n+\n+\t\t\tfinal byte[] ep = e.path;\n+\t\t\tif (childIdx < childCnt) {\n+\t\t\t\tfinal DirCacheTree st = children[childIdx];\n+\t\t\t\tif (st.contains(ep, pathOffset, ep.length)) {\n+\t\t\t\t\tfinal int stOffset = pathOffset + st.nameLength() + 1;\n+\t\t\t\t\tst.writeTree(cache, entryIdx, stOffset, ow);\n+\n+\t\t\t\t\tsize += FileMode.TREE.copyToLength();\n+\t\t\t\t\tsize += st.nameLength();\n+\t\t\t\t\tsize += OBJECT_ID_LENGTH + 2;\n+\n+\t\t\t\t\tentryIdx += st.entrySpan;\n+\t\t\t\t\tchildIdx++;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tfinal FileMode mode = e.getFileMode();\n+\t\t\tif (mode.getObjectType() == Constants.OBJ_BAD)\n+\t\t\t\tthrow new UnmergedPathException(e);\n+\n+\t\t\tsize += mode.copyToLength();\n+\t\t\tsize += ep.length - pathOffset;\n+\t\t\tsize += OBJECT_ID_LENGTH + 2;\n+\t\t\tentryIdx++;\n+\t\t}\n+\n+\t\treturn size;\n+\t}\n+\n \tprivate void appendName(final StringBuilder r) {\n \t\tif (parent != null) {\n \t\t\tparent.appendName(r);\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java\nnew file mode 100644\nindex 0000000..17a3965\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java\n@@ -0,0 +1,67 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.errors;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.dircache.DirCacheEntry;\n+\n+/**\n+ * Indicates one or more paths in a DirCache have non-zero stages present.\n+ */\n+public class UnmergedPathException extends IOException {\n+\tprivate static final long serialVersionUID = 1L;\n+\n+\tprivate final DirCacheEntry entry;\n+\n+\t/**\n+\t * Create a new unmerged path exception.\n+\t * \n+\t * @param dce\n+\t *            the first non-zero stage of the unmerged path.\n+\t */\n+\tpublic UnmergedPathException(final DirCacheEntry dce) {\n+\t\tsuper(\"Unmerged path: \" + dce.getPathString());\n+\t\tentry = dce;\n+\t}\n+\n+\t/** @return the first non-zero stage of the unmerged path */\n+\tpublic DirCacheEntry getDirCacheEntry() {\n+\t\treturn entry;\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java\nindex fe5f2f6..cf42f37 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java\n@@ -191,6 +191,13 @@ public void copyTo(final OutputStream os) throws IOException {\n \t}\n \n \t/**\n+\t * @return the number of bytes written by {@link #copyTo(OutputStream)}.\n+\t */\n+\tpublic int copyToLength() {\n+\t\treturn octalBytes.length;\n+\t}\n+\n+\t/**\n \t * Get the object type that should appear for this type of mode.\n \t * <p>\n \t * See the object type constants in {@link Constants}.\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java\nindex e84798a..546cc68 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java\n@@ -155,10 +155,18 @@ public ObjectId writeTree(final Tree t) throws IOException {\n \t\t\to.write(0);\n \t\t\tid.copyRawTo(o);\n \t\t}\n-\t\treturn writeTree(o.toByteArray());\n+\t\treturn writeCanonicalTree(o.toByteArray());\n \t}\n \n-\tprivate ObjectId writeTree(final byte[] b) throws IOException {\n+\t/**\n+\t * Write a canonical tree to the object database.\n+\t *\n+\t * @param b\n+\t *            the canonical encoding of the tree object.\n+\t * @return SHA-1 of the tree\n+\t * @throws IOException\n+\t */\n+\tpublic ObjectId writeCanonicalTree(final byte[] b) throws IOException {\n \t\treturn writeTree(b.length, new ByteArrayInputStream(b));\n \t}\n \n-- \n1.6.1.399.g0d272\n"},{"id":"101576","messageId":"1232666890-23488-6-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-5-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 05/10] Allow a DirCache to be created with no backing store file","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:05Z","receivedAt":"2009-01-22T23:28:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This permits using a DirCache as a temporary storage area in memory\nonly, with no chance of it being written out to disk.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/dircache/DirCache.java    |   17 +++++++++++++++++\n 1 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\nindex b3c57ad..c5a4f91 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n@@ -111,6 +111,17 @@ static int cmp(final byte[] aPath, final int aLen, final byte[] bPath,\n \t}\n \n \t/**\n+\t * Create a new empty index which is never stored on disk.\n+\t * \n+\t * @return an empty cache which has no backing store file. The cache may not\n+\t *         be read or written, but it may be queried and updated (in\n+\t *         memory).\n+\t */\n+\tpublic static DirCache newInCore() {\n+\t\treturn new DirCache(null);\n+\t}\n+\n+\t/**\n \t * Create a new in-core index representation and read an index from disk.\n \t * <p>\n \t * The new index will be read before it is returned to the caller. Read\n@@ -297,6 +308,8 @@ void replace(final DirCacheEntry[] e, final int cnt) {\n \t *             library does not support.\n \t */\n \tpublic void read() throws IOException, CorruptObjectException {\n+\t\tif (liveFile == null)\n+\t\t\tthrow new IOException(\"DirCache does not have a backing file\");\n \t\tif (!liveFile.exists())\n \t\t\tclear();\n \t\telse if (liveFile.lastModified() != lastModified) {\n@@ -407,6 +420,8 @@ private static boolean is_DIRC(final byte[] hdr) {\n \t *             hold the lock.\n \t */\n \tpublic boolean lock() throws IOException {\n+\t\tif (liveFile == null)\n+\t\t\tthrow new IOException(\"DirCache does not have a backing file\");\n \t\tfinal LockFile tmp = new LockFile(liveFile);\n \t\tif (tmp.lock()) {\n \t\t\ttmp.setNeedStatInformation(true);\n@@ -515,6 +530,8 @@ public boolean commit() {\n \t}\n \n \tprivate void requireLocked(final LockFile tmp) {\n+\t\tif (liveFile == null)\n+\t\t\tthrow new IllegalStateException(\"DirCache is not locked\");\n \t\tif (tmp == null)\n \t\t\tthrow new IllegalStateException(\"DirCache \"\n \t\t\t\t\t+ liveFile.getAbsolutePath() + \" not locked.\");\n-- \n1.6.1.399.g0d272\n"},{"id":"101573","messageId":"1232666890-23488-7-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-6-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 06/10] Allow CanonicalTreeParsers to be created with a UTF-8 path prefix","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:06Z","receivedAt":"2009-01-22T23:28:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Creating an iterator with a path prefix permits a tree to be\n\"mounted\" at a different part of a repository, permitting more\nsophisticated merge strategies beyond just 1:1 path matching.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/treewalk/AbstractTreeIterator.java        |   31 ++++++++++++++++++++\n .../spearce/jgit/treewalk/CanonicalTreeParser.java |   30 +++++++++++++++++++\n .../src/org/spearce/jgit/treewalk/TreeWalk.java    |    2 +-\n 3 files changed, 62 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\nindex 791056c..62ca69c 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java\n@@ -172,6 +172,37 @@ protected AbstractTreeIterator(final String prefix) {\n \t}\n \n \t/**\n+\t * Create a new iterator with no parent and a prefix.\n+\t * <p>\n+\t * The prefix path supplied is inserted in front of all paths generated by\n+\t * this iterator. It is intended to be used when an iterator is being\n+\t * created for a subsection of an overall repository and needs to be\n+\t * combined with other iterators that are created to run over the entire\n+\t * repository namespace.\n+\t *\n+\t * @param prefix\n+\t *            position of this iterator in the repository tree. The value\n+\t *            may be null or the empty array to indicate the prefix is the\n+\t *            root of the repository. A trailing slash ('/') is\n+\t *            automatically appended if the prefix does not end in '/'.\n+\t */\n+\tprotected AbstractTreeIterator(final byte[] prefix) {\n+\t\tparent = null;\n+\n+\t\tif (prefix != null && prefix.length > 0) {\n+\t\t\tpathLen = prefix.length;\n+\t\t\tpath = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)];\n+\t\t\tSystem.arraycopy(prefix, 0, path, 0, pathLen);\n+\t\t\tif (path[pathLen - 1] != '/')\n+\t\t\t\tpath[pathLen++] = '/';\n+\t\t\tpathOffset = pathLen;\n+\t\t} else {\n+\t\t\tpath = new byte[DEFAULT_PATH_SIZE];\n+\t\t\tpathOffset = 0;\n+\t\t}\n+\t}\n+\t\n+\t/**\n \t * Create an iterator for a subtree of an existing iterator.\n \t * \n \t * @param p\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java\nindex 2bcf792..ed883bd 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java\n@@ -67,6 +67,36 @@ public CanonicalTreeParser() {\n \t\traw = EMPTY;\n \t}\n \n+\t/**\n+\t * Create a new parser for a tree appearing in a subset of a repository.\n+\t * \n+\t * @param prefix\n+\t *            position of this iterator in the repository tree. The value\n+\t *            may be null or the empty array to indicate the prefix is the\n+\t *            root of the repository. A trailing slash ('/') is\n+\t *            automatically appended if the prefix does not end in '/'.\n+\t * @param repo\n+\t *            repository to load the tree data from.\n+\t * @param treeId\n+\t *            identity of the tree being parsed; used only in exception\n+\t *            messages if data corruption is found.\n+\t * @param curs\n+\t *            a window cursor to use during data access from the repository.\n+\t * @throws MissingObjectException\n+\t *             the object supplied is not available from the repository.\n+\t * @throws IncorrectObjectTypeException\n+\t *             the object supplied as an argument is not actually a tree and\n+\t *             cannot be parsed as though it were a tree.\n+\t * @throws IOException\n+\t *             a loose object or pack file could not be read.\n+\t */\n+\tpublic CanonicalTreeParser(final byte[] prefix, final Repository repo,\n+\t\t\tfinal ObjectId treeId, final WindowCursor curs)\n+\t\t\tthrows IncorrectObjectTypeException, IOException {\n+\t\tsuper(prefix);\n+\t\treset(repo, treeId, curs);\n+\t}\n+\n \tprivate CanonicalTreeParser(final CanonicalTreeParser p) {\n \t\tsuper(p);\n \t}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\nindex 22040e3..416e027 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java\n@@ -354,7 +354,7 @@ public void reset(final AnyObjectId[] ids) throws MissingObjectException,\n \t\t\t\to = trees[i];\n \t\t\t\twhile (o.parent != null)\n \t\t\t\t\to = o.parent;\n-\t\t\t\tif (o instanceof CanonicalTreeParser) {\n+\t\t\t\tif (o instanceof CanonicalTreeParser && o.pathOffset == 0) {\n \t\t\t\t\to.matches = null;\n \t\t\t\t\to.matchShift = 0;\n \t\t\t\t\t((CanonicalTreeParser) o).reset(db, ids[i], curs);\n-- \n1.6.1.399.g0d272\n"},{"id":"101575","messageId":"1232666890-23488-8-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-7-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 07/10] Recursively load an entire tree into a DirCacheBuilder","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:07Z","receivedAt":"2009-01-22T23:28:07Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This implements the DirCache portion of \"git read-tree\", where a\ntree can be recursively read into a DirCache instance without an\nimpact on the working directory.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/dircache/DirCacheBuilder.java |   65 ++++++++++++++++++++\n 1 files changed, 65 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java\nindex 3a37054..10161fa 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java\n@@ -37,8 +37,16 @@\n \n package org.spearce.jgit.dircache;\n \n+import java.io.IOException;\n import java.util.Arrays;\n \n+import org.spearce.jgit.lib.AnyObjectId;\n+import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.lib.WindowCursor;\n+import org.spearce.jgit.treewalk.AbstractTreeIterator;\n+import org.spearce.jgit.treewalk.CanonicalTreeParser;\n+import org.spearce.jgit.treewalk.TreeWalk;\n+\n /**\n  * Updates a {@link DirCache} by adding individual {@link DirCacheEntry}s.\n  * <p>\n@@ -112,6 +120,63 @@ public void keep(final int pos, int cnt) {\n \t\tfastKeep(pos, cnt);\n \t}\n \n+\t/**\n+\t * Recursively add an entire tree into this builder.\n+\t * <p>\n+\t * If pathPrefix is \"a/b\" and the tree contains file \"c\" then the resulting\n+\t * DirCacheEntry will have the path \"a/b/c\".\n+\t * <p>\n+\t * All entries are inserted at stage 0, therefore assuming that the\n+\t * application will not insert any other paths with the same pathPrefix.\n+\t * \n+\t * @param pathPrefix\n+\t *            UTF-8 encoded prefix to mount the tree's entries at. If the\n+\t *            path does not end with '/' one will be automatically inserted\n+\t *            as necessary.\n+\t * @param db\n+\t *            repository the tree(s) will be read from during recursive\n+\t *            traversal. This must be the same repository that the resulting\n+\t *            DirCache would be written out to (or used in) otherwise the\n+\t *            caller is simply asking for deferred MissingObjectExceptions.\n+\t * @param tree\n+\t *            the tree to recursively add. This tree's contents will appear\n+\t *            under <code>pathPrefix</code>. The ObjectId must be that of a\n+\t *            tree; the caller is responsible for dereferencing a tag or\n+\t *            commit (if necessary).\n+\t * @throws IOException\n+\t *             a tree cannot be read to iterate through its entries.\n+\t */\n+\tpublic void addTree(final byte[] pathPrefix, final Repository db,\n+\t\t\tfinal AnyObjectId tree) throws IOException {\n+\t\tfinal TreeWalk tw = new TreeWalk(db);\n+\t\ttw.reset();\n+\t\tfinal WindowCursor curs = new WindowCursor();\n+\t\ttry {\n+\t\t\ttw.addTree(new CanonicalTreeParser(pathPrefix, db, tree\n+\t\t\t\t\t.toObjectId(), curs));\n+\t\t} finally {\n+\t\t\tcurs.release();\n+\t\t}\n+\t\ttw.setRecursive(true);\n+\t\tif (tw.next()) {\n+\t\t\tfinal DirCacheEntry newEntry = toEntry(tw);\n+\t\t\tbeforeAdd(newEntry);\n+\t\t\tfastAdd(newEntry);\n+\t\t\twhile (tw.next())\n+\t\t\t\tfastAdd(toEntry(tw));\n+\t\t}\n+\t}\n+\n+\tprivate DirCacheEntry toEntry(final TreeWalk tw) {\n+\t\tfinal DirCacheEntry e = new DirCacheEntry(tw.getRawPath());\n+\t\tfinal AbstractTreeIterator i;\n+\n+\t\ti = tw.getTree(0, AbstractTreeIterator.class);\n+\t\te.setFileMode(tw.getFileMode(0));\n+\t\te.setObjectIdFromRaw(i.idBuffer(), i.idOffset());\n+\t\treturn e;\n+\t}\n+\n \tpublic void finish() {\n \t\tif (!sorted)\n \t\t\tresort();\n-- \n1.6.1.399.g0d272\n"},{"id":"101572","messageId":"1232666890-23488-9-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-8-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 08/10] Allow DirCacheEntry instances to be created with stage > 0","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:08Z","receivedAt":"2009-01-22T23:28:08Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"As the stage is part of the sorting criteria for DirCacheEntry\nobjects we don't allow the stage to be modified on the fly in\nan existing instance.  Instead the stage must be set by reading\nit from the on-disk format or by creating a new entry with the\nproper path and stage components.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/dircache/DirCacheEntry.java   |   52 +++++++++++++++++---\n 1 files changed, 45 insertions(+), 7 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\nindex 355cd3e..9304501 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java\n@@ -60,6 +60,18 @@\n public class DirCacheEntry {\n \tprivate static final byte[] nullpad = new byte[8];\n \n+\t/** The standard (fully merged) stage for an entry. */\n+\tpublic static final int STAGE_0 = 0;\n+\n+\t/** The base tree revision for an entry. */\n+\tpublic static final int STAGE_1 = 1;\n+\n+\t/** The first tree revision (usually called \"ours\"). */\n+\tpublic static final int STAGE_2 = 2;\n+\n+\t/** The second tree revision (usually called \"theirs\"). */\n+\tpublic static final int STAGE_3 = 3;\n+\n \t// private static final int P_CTIME = 0;\n \n \t// private static final int P_CTIME_NSEC = 4;\n@@ -141,8 +153,8 @@ DirCacheEntry(final byte[] sharedInfo, final int infoAt,\n \t}\n \n \t/**\n-\t * Create an empty entry.\n-\t *\n+\t * Create an empty entry at stage 0.\n+\t * \n \t * @param newPath\n \t *            name of the cache entry.\n \t */\n@@ -151,20 +163,46 @@ public DirCacheEntry(final String newPath) {\n \t}\n \n \t/**\n-\t * Create an empty entry.\n-\t *\n+\t * Create an empty entry at the specified stage.\n+\t * \n+\t * @param newPath\n+\t *            name of the cache entry.\n+\t * @param stage\n+\t *            the stage index of the new entry.\n+\t */\n+\tpublic DirCacheEntry(final String newPath, final int stage) {\n+\t\tthis(Constants.encode(newPath), stage);\n+\t}\n+\n+\t/**\n+\t * Create an empty entry at stage 0.\n+\t * \n \t * @param newPath\n \t *            name of the cache entry, in the standard encoding.\n \t */\n \tpublic DirCacheEntry(final byte[] newPath) {\n+\t\tthis(newPath, STAGE_0);\n+\t}\n+\n+\t/**\n+\t * Create an empty entry at the specified stage.\n+\t * \n+\t * @param newPath\n+\t *            name of the cache entry, in the standard encoding.\n+\t * @param stage\n+\t *            the stage index of the new entry.\n+\t */\n+\tpublic DirCacheEntry(final byte[] newPath, final int stage) {\n \t\tinfo = new byte[INFO_LEN];\n \t\tinfoOffset = 0;\n-\n \t\tpath = newPath;\n+\n+\t\tint flags = ((stage & 0x3) << 12);\n \t\tif (path.length < NAME_MASK)\n-\t\t\tNB.encodeInt16(info, infoOffset + P_FLAGS, path.length);\n+\t\t\tflags |= path.length;\n \t\telse\n-\t\t\tNB.encodeInt16(info, infoOffset + P_FLAGS, NAME_MASK);\n+\t\t\tflags |= NAME_MASK;\n+\t\tNB.encodeInt16(info, infoOffset + P_FLAGS, flags);\n \t}\n \n \tvoid write(final OutputStream os) throws IOException {\n-- \n1.6.1.399.g0d272\n"},{"id":"101574","messageId":"1232666890-23488-10-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-9-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 09/10] Define a basic merge API, and a two-way tree merge strategy","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:09Z","receivedAt":"2009-01-22T23:28:09Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This basic merge implementation is sufficient to merge two commits in\nmemory and write the result out as a new commit, without having a work\ntree on the local filesystem.  It is therefore suitable for use within\na batch server process where human intervention is not available to\nresolve conflicts.\n\nThis API should permit extending it with the working tree and a copy\nof the work tree's DirCache, so edits in the tree can be merged in\nparallel with edits from commits.  But the functionality is not yet\nimplemented, so it is still a pie-in-the-sky concept.\n\nThe main strategy \"simple-two-way-in-core\" provides a basic 3 way\nmerge on the path level only.  File contents are never patched by\nthis strategy, making it somewhat safe for automatic merges.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/merge/MergeStrategy.java  |  134 ++++++++++++\n .../src/org/spearce/jgit/merge/Merger.java         |  213 ++++++++++++++++++++\n .../org/spearce/jgit/merge/StrategyOneSided.java   |   98 +++++++++\n .../jgit/merge/StrategySimpleTwoWayInCore.java     |  179 ++++++++++++++++\n 4 files changed, 624 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java\nnew file mode 100644\nindex 0000000..d28dcc1\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java\n@@ -0,0 +1,134 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.merge;\n+\n+import java.util.HashMap;\n+\n+import org.spearce.jgit.lib.Repository;\n+\n+/**\n+ * A method of combining two or more trees together to form an output tree.\n+ * <p>\n+ * Different strategies may employ different techniques for deciding which paths\n+ * (and ObjectIds) to carry from the input trees into the final output tree.\n+ */\n+public abstract class MergeStrategy {\n+\t/** Simple strategy that sets the output tree to the first input tree. */\n+\tpublic static final MergeStrategy OURS = new StrategyOneSided(\"ours\", 0);\n+\n+\t/** Simple strategy that sets the output tree to the second input tree. */\n+\tpublic static final MergeStrategy THEIRS = new StrategyOneSided(\"theirs\", 1);\n+\n+\t/** Simple strategy to merge paths, without simultaneous edits. */\n+\tpublic static final MergeStrategy SIMPLE_TWO_WAY_IN_CORE = StrategySimpleTwoWayInCore.INSTANCE;\n+\n+\tprivate static final HashMap<String, MergeStrategy> STRATEGIES = new HashMap<String, MergeStrategy>();\n+\n+\tstatic {\n+\t\tregister(OURS);\n+\t\tregister(THEIRS);\n+\t\tregister(SIMPLE_TWO_WAY_IN_CORE);\n+\t}\n+\n+\t/**\n+\t * Register a merge strategy so it can later be obtained by name.\n+\t * \n+\t * @param imp\n+\t *            the strategy to register.\n+\t * @throws IllegalArgumentException\n+\t *             a strategy by the same name has already been registered.\n+\t */\n+\tpublic static void register(final MergeStrategy imp) {\n+\t\tregister(imp.getName(), imp);\n+\t}\n+\n+\t/**\n+\t * Register a merge strategy so it can later be obtained by name.\n+\t * \n+\t * @param name\n+\t *            name the strategy can be looked up under.\n+\t * @param imp\n+\t *            the strategy to register.\n+\t * @throws IllegalArgumentException\n+\t *             a strategy by the same name has already been registered.\n+\t */\n+\tpublic static synchronized void register(final String name,\n+\t\t\tfinal MergeStrategy imp) {\n+\t\tif (STRATEGIES.containsKey(name))\n+\t\t\tthrow new IllegalArgumentException(\"Merge strategy \\\"\" + name\n+\t\t\t\t\t+ \"\\\" already exists as a default strategy\");\n+\t\tSTRATEGIES.put(name, imp);\n+\t}\n+\n+\t/**\n+\t * Locate a strategy by name.\n+\t * \n+\t * @param name\n+\t *            name of the strategy to locate.\n+\t * @return the strategy instance; null if no strategy matches the name.\n+\t */\n+\tpublic static synchronized MergeStrategy get(final String name) {\n+\t\treturn STRATEGIES.get(name);\n+\t}\n+\n+\t/**\n+\t * Get all registered strategies.\n+\t * \n+\t * @return the registered strategy instances. No inherit order is returned;\n+\t *         the caller may modify (and/or sort) the returned array if\n+\t *         necessary to obtain a reasonable ordering.\n+\t */\n+\tpublic static synchronized MergeStrategy[] get() {\n+\t\tfinal MergeStrategy[] r = new MergeStrategy[STRATEGIES.size()];\n+\t\tSTRATEGIES.values().toArray(r);\n+\t\treturn r;\n+\t}\n+\n+\t/** @return default name of this strategy implementation. */\n+\tpublic abstract String getName();\n+\n+\t/**\n+\t * Create a new merge instance.\n+\t * \n+\t * @param db\n+\t *            repository database the merger will read from, and eventually\n+\t *            write results back to.\n+\t * @return the new merge instance which implements this strategy.\n+\t */\n+\tpublic abstract Merger newMerger(Repository db);\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java\nnew file mode 100644\nindex 0000000..04990a1\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java\n@@ -0,0 +1,213 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.merge;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.errors.IncorrectObjectTypeException;\n+import org.spearce.jgit.lib.AnyObjectId;\n+import org.spearce.jgit.lib.Constants;\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.ObjectWriter;\n+import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.lib.WindowCursor;\n+import org.spearce.jgit.revwalk.RevCommit;\n+import org.spearce.jgit.revwalk.RevObject;\n+import org.spearce.jgit.revwalk.RevTree;\n+import org.spearce.jgit.revwalk.RevWalk;\n+import org.spearce.jgit.revwalk.filter.RevFilter;\n+import org.spearce.jgit.treewalk.AbstractTreeIterator;\n+import org.spearce.jgit.treewalk.CanonicalTreeParser;\n+import org.spearce.jgit.treewalk.EmptyTreeIterator;\n+\n+/**\n+ * Instance of a specific {@link MergeStrategy} for a single {@link Repository}.\n+ */\n+public abstract class Merger {\n+\t/** The repository this merger operates on. */\n+\tprotected final Repository db;\n+\n+\t/** A RevWalk for computing merge bases, or listing incoming commits. */\n+\tprotected final RevWalk walk;\n+\n+\tprivate ObjectWriter writer;\n+\n+\t/** The original objects supplied in the merge; this can be any tree-ish. */\n+\tprotected RevObject[] sourceObjects;\n+\n+\t/** If {@link #sourceObjects}[i] is a commit, this is the commit. */\n+\tprotected RevCommit[] sourceCommits;\n+\n+\t/** The trees matching every entry in {@link #sourceObjects}. */\n+\tprotected RevTree[] sourceTrees;\n+\n+\t/**\n+\t * Create a new merge instance for a repository.\n+\t * \n+\t * @param local\n+\t *            the repository this merger will read and write data on.\n+\t */\n+\tprotected Merger(final Repository local) {\n+\t\tdb = local;\n+\t\twalk = new RevWalk(db);\n+\t}\n+\n+\t/**\n+\t * @return the repository this merger operates on.\n+\t */\n+\tpublic Repository getRepository() {\n+\t\treturn db;\n+\t}\n+\n+\t/**\n+\t * @return an object writer to create objects in {@link #getRepository()}.\n+\t */\n+\tpublic ObjectWriter getObjectWriter() {\n+\t\tif (writer == null)\n+\t\t\twriter = new ObjectWriter(getRepository());\n+\t\treturn writer;\n+\t}\n+\n+\t/**\n+\t * Merge together two or more tree-ish objects.\n+\t * <p>\n+\t * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at\n+\t * trees or commits may be passed as input objects.\n+\t * \n+\t * @param tips\n+\t *            source trees to be combined together. The merge base is not\n+\t *            included in this set.\n+\t * @return true if the merge was completed without conflicts; false if the\n+\t *         merge strategy cannot handle this merge or there were conflicts\n+\t *         preventing it from automatically resolving all paths.\n+\t * @throws IncorrectObjectTypeException\n+\t *             one of the input objects is not a commit, but the strategy\n+\t *             requires it to be a commit.\n+\t * @throws IOException\n+\t *             one or more sources could not be read, or outputs could not\n+\t *             be written to the Repository.\n+\t */\n+\tpublic final boolean merge(final AnyObjectId[] tips) throws IOException {\n+\t\tsourceObjects = new RevObject[tips.length];\n+\t\tfor (int i = 0; i < tips.length; i++)\n+\t\t\tsourceObjects[i] = walk.parseAny(tips[i]);\n+\n+\t\tsourceCommits = new RevCommit[sourceObjects.length];\n+\t\tfor (int i = 0; i < sourceObjects.length; i++) {\n+\t\t\ttry {\n+\t\t\t\tsourceCommits[i] = walk.parseCommit(sourceObjects[i]);\n+\t\t\t} catch (IncorrectObjectTypeException err) {\n+\t\t\t\tsourceCommits[i] = null;\n+\t\t\t}\n+\t\t}\n+\n+\t\tsourceTrees = new RevTree[sourceObjects.length];\n+\t\tfor (int i = 0; i < sourceObjects.length; i++)\n+\t\t\tsourceTrees[i] = walk.parseTree(sourceObjects[i]);\n+\n+\t\treturn mergeImpl();\n+\t}\n+\n+\t/**\n+\t * Create an iterator to walk the merge base of two commits.\n+\t * \n+\t * @param aIdx\n+\t *            index of the first commit in {@link #sourceObjects}.\n+\t * @param bIdx\n+\t *            index of the second commit in {@link #sourceObjects}.\n+\t * @return the new iterator\n+\t * @throws IncorrectObjectTypeException\n+\t *             one of the input objects is not a commit.\n+\t * @throws IOException\n+\t *             objects are missing or multiple merge bases were found.\n+\t */\n+\tprotected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx)\n+\t\t\tthrows IOException {\n+\t\tif (sourceCommits[aIdx] == null)\n+\t\t\tthrow new IncorrectObjectTypeException(sourceObjects[aIdx],\n+\t\t\t\t\tConstants.TYPE_COMMIT);\n+\t\tif (sourceCommits[bIdx] == null)\n+\t\t\tthrow new IncorrectObjectTypeException(sourceObjects[bIdx],\n+\t\t\t\t\tConstants.TYPE_COMMIT);\n+\n+\t\twalk.reset();\n+\t\twalk.setRevFilter(RevFilter.MERGE_BASE);\n+\t\twalk.markStart(sourceCommits[aIdx]);\n+\t\twalk.markStart(sourceCommits[bIdx]);\n+\t\tfinal RevCommit base = walk.next();\n+\t\tif (base == null)\n+\t\t\treturn new EmptyTreeIterator();\n+\t\tfinal RevCommit base2 = walk.next();\n+\t\tif (base2 != null) {\n+\t\t\tthrow new IOException(\"Multiple merge bases for:\" + \"\\n  \"\n+\t\t\t\t\t+ sourceCommits[aIdx].name() + \"\\n  \"\n+\t\t\t\t\t+ sourceCommits[bIdx].name() + \"found:\" + \"\\n  \"\n+\t\t\t\t\t+ base.name() + \"\\n  \" + base2.name());\n+\t\t}\n+\t\tfinal WindowCursor curs = new WindowCursor();\n+\t\ttry {\n+\t\t\treturn new CanonicalTreeParser(null, db, base.getTree(), curs);\n+\t\t} finally {\n+\t\t\tcurs.release();\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Execute the merge.\n+\t * <p>\n+\t * This method is called from {@link #merge(AnyObjectId[])} after the\n+\t * {@link #sourceObjects}, {@link #sourceCommits} and {@link #sourceTrees}\n+\t * have been populated.\n+\t * \n+\t * @return true if the merge was completed without conflicts; false if the\n+\t *         merge strategy cannot handle this merge or there were conflicts\n+\t *         preventing it from automatically resolving all paths.\n+\t * @throws IncorrectObjectTypeException\n+\t *             one of the input objects is not a commit, but the strategy\n+\t *             requires it to be a commit.\n+\t * @throws IOException\n+\t *             one or more sources could not be read, or outputs could not\n+\t *             be written to the Repository.\n+\t */\n+\tprotected abstract boolean mergeImpl() throws IOException;\n+\n+\t/**\n+\t * @return resulting tree, if {@link #merge(AnyObjectId[])} returned true.\n+\t */\n+\tpublic abstract ObjectId getResultTreeId();\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java\nnew file mode 100644\nindex 0000000..0c3dcc2\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java\n@@ -0,0 +1,98 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.merge;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.Repository;\n+\n+/**\n+ * Trivial merge strategy to make the resulting tree exactly match an input.\n+ * <p>\n+ * This strategy can be used to cauterize an entire side branch of history, by\n+ * setting the output tree to one of the inputs, and ignoring any of the paths\n+ * of the other inputs.\n+ */\n+public class StrategyOneSided extends MergeStrategy {\n+\tprivate final String strategyName;\n+\n+\tprivate final int treeIndex;\n+\n+\t/**\n+\t * Create a new merge strategy to select a specific input tree.\n+\t * \n+\t * @param name\n+\t *            name of this strategy.\n+\t * @param index\n+\t *            the position of the input tree to accept as the result.\n+\t */\n+\tprotected StrategyOneSided(final String name, final int index) {\n+\t\tstrategyName = name;\n+\t\ttreeIndex = index;\n+\t}\n+\n+\t@Override\n+\tpublic String getName() {\n+\t\treturn strategyName;\n+\t}\n+\n+\t@Override\n+\tpublic Merger newMerger(final Repository db) {\n+\t\treturn new OneSide(db, treeIndex);\n+\t}\n+\n+\tprotected static class OneSide extends Merger {\n+\t\tprivate final int treeIndex;\n+\n+\t\tprotected OneSide(final Repository local, final int index) {\n+\t\t\tsuper(local);\n+\t\t\ttreeIndex = index;\n+\t\t}\n+\n+\t\t@Override\n+\t\tprotected boolean mergeImpl() throws IOException {\n+\t\t\treturn treeIndex < sourceTrees.length;\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic ObjectId getResultTreeId() {\n+\t\t\treturn sourceTrees[treeIndex];\n+\t\t}\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java\nnew file mode 100644\nindex 0000000..893add9\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java\n@@ -0,0 +1,179 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.merge;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.dircache.DirCache;\n+import org.spearce.jgit.dircache.DirCacheBuilder;\n+import org.spearce.jgit.dircache.DirCacheEntry;\n+import org.spearce.jgit.errors.UnmergedPathException;\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.treewalk.AbstractTreeIterator;\n+import org.spearce.jgit.treewalk.NameConflictTreeWalk;\n+\n+/**\n+ * Merges two commits together in-memory, ignoring any working directory.\n+ * <p>\n+ * The strategy chooses a path from one of the two input trees if the path is\n+ * unchanged in the other relative to their common merge base tree. This is a\n+ * trivial 3-way merge (at the file path level only).\n+ * <p>\n+ * Modifications of the same file path (content and/or file mode) by both input\n+ * trees will cause a merge conflict, as this strategy does not attempt to merge\n+ * file contents.\n+ */\n+public class StrategySimpleTwoWayInCore extends MergeStrategy {\n+\tstatic final MergeStrategy INSTANCE = new StrategySimpleTwoWayInCore();\n+\n+\t/** Create a new instance of the strategy. */\n+\tprotected StrategySimpleTwoWayInCore() {\n+\t\t//\n+\t}\n+\n+\t@Override\n+\tpublic String getName() {\n+\t\treturn \"simple-two-way-in-core\";\n+\t}\n+\n+\t@Override\n+\tpublic Merger newMerger(final Repository db) {\n+\t\treturn new InCoreMerger(db);\n+\t}\n+\n+\tprivate static class InCoreMerger extends Merger {\n+\t\tprivate static final int T_BASE = 0;\n+\n+\t\tprivate static final int T_OURS = 1;\n+\n+\t\tprivate static final int T_THEIRS = 2;\n+\n+\t\tprivate final NameConflictTreeWalk tw;\n+\n+\t\tprivate final DirCache cache;\n+\n+\t\tprivate DirCacheBuilder builder;\n+\n+\t\tprivate ObjectId resultTree;\n+\n+\t\tInCoreMerger(final Repository local) {\n+\t\t\tsuper(local);\n+\t\t\ttw = new NameConflictTreeWalk(db);\n+\t\t\tcache = DirCache.newInCore();\n+\t\t}\n+\n+\t\t@Override\n+\t\tprotected boolean mergeImpl() throws IOException {\n+\t\t\tif (sourceTrees.length != 2)\n+\t\t\t\treturn false;\n+\n+\t\t\ttw.reset();\n+\t\t\ttw.addTree(mergeBase(0, 1));\n+\t\t\ttw.addTree(sourceTrees[0]);\n+\t\t\ttw.addTree(sourceTrees[1]);\n+\n+\t\t\tboolean hasConflict = false;\n+\t\t\tbuilder = cache.builder();\n+\t\t\twhile (tw.next()) {\n+\t\t\t\tfinal int modeO = tw.getRawMode(T_OURS);\n+\t\t\t\tfinal int modeT = tw.getRawMode(T_THEIRS);\n+\t\t\t\tif (modeO == modeT && tw.idEqual(T_OURS, T_THEIRS)) {\n+\t\t\t\t\tsame();\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tfinal int modeB = tw.getRawMode(T_BASE);\n+\t\t\t\tif (modeB == modeO && tw.idEqual(T_BASE, T_OURS))\n+\t\t\t\t\tadd(T_THEIRS, DirCacheEntry.STAGE_0);\n+\t\t\t\telse if (modeB == modeT && tw.idEqual(T_BASE, T_THEIRS))\n+\t\t\t\t\tadd(T_OURS, DirCacheEntry.STAGE_0);\n+\t\t\t\telse {\n+\t\t\t\t\tconflict();\n+\t\t\t\t\thasConflict = true;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tbuilder.finish();\n+\t\t\tbuilder = null;\n+\n+\t\t\tif (hasConflict)\n+\t\t\t\treturn false;\n+\t\t\ttry {\n+\t\t\t\tresultTree = cache.writeTree(getObjectWriter());\n+\t\t\t\treturn true;\n+\t\t\t} catch (UnmergedPathException upe) {\n+\t\t\t\tresultTree = null;\n+\t\t\t\treturn false;\n+\t\t\t}\n+\t\t}\n+\n+\t\tprivate void same() throws IOException {\n+\t\t\tif (tw.isSubtree())\n+\t\t\t\tbuilder.addTree(tw.getRawPath(), db, tw.getObjectId(1));\n+\t\t\telse\n+\t\t\t\tadd(T_OURS, DirCacheEntry.STAGE_0);\n+\t\t}\n+\n+\t\tprivate void conflict() {\n+\t\t\tadd(T_BASE, DirCacheEntry.STAGE_1);\n+\t\t\tadd(T_OURS, DirCacheEntry.STAGE_2);\n+\t\t\tadd(T_THEIRS, DirCacheEntry.STAGE_3);\n+\t\t}\n+\n+\t\tprivate void add(final int tree, final int stage) {\n+\t\t\tfinal AbstractTreeIterator i = getTree(tree);\n+\t\t\tif (i != null) {\n+\t\t\t\tfinal DirCacheEntry e;\n+\n+\t\t\t\te = new DirCacheEntry(tw.getRawPath(), stage);\n+\t\t\t\te.setObjectIdFromRaw(i.idBuffer(), i.idOffset());\n+\t\t\t\te.setFileMode(tw.getFileMode(tree));\n+\t\t\t\tbuilder.add(e);\n+\t\t\t}\n+\t\t}\n+\n+\t\tprivate AbstractTreeIterator getTree(final int tree) {\n+\t\t\treturn tw.getTree(tree, AbstractTreeIterator.class);\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic ObjectId getResultTreeId() {\n+\t\t\treturn resultTree;\n+\t\t}\n+\t}\n+}\n-- \n1.6.1.399.g0d272\n"},{"id":"101577","messageId":"1232666890-23488-11-git-send-email-spearce@spearce.org","threadId":"17310","inReplyTo":"1232666890-23488-10-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 10/10] Add a few simple merge test cases","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-01-22T23:28:10Z","receivedAt":"2009-01-22T23:28:10Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/jgit/test/resources/create-second-pack |   13 +++-\n ...ck-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx |  Bin 0 -> 1296 bytes\n ...k-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack |  Bin 0 -> 562 bytes\n ...ck-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx |  Bin 1088 -> 1100 bytes\n ...ck-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx |  Bin 2696 -> 2976 bytes\n ...k-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack |  Bin 5956 -> 5901 bytes\n .../org/spearce/jgit/test/resources/packed-refs    |    4 +-\n .../org/spearce/jgit/lib/RepositoryTestCase.java   |    3 +-\n .../org/spearce/jgit/merge/SimpleMergeTest.java    |   86 ++++++++++++++++++++\n .../org/spearce/jgit/transport/TransportTest.java  |    2 +-\n 10 files changed, 104 insertions(+), 4 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx\n create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack\nindex 052877d..5501a67 100755\n--- a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack\n+++ b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack\n@@ -138,7 +138,18 @@ done\n \n git repack -d\n \n+git checkout -b f a\n+mkdir f\n+echo \"an eff\" >f/f\n+git add f/f\n+git commit -m \"An eff\"\n+git checkout -b g a\n+mkdir f\n+echo \"an F\" >f/f\n+git add f/f\n+git commit -m \"An F\"\n+git repack -d\n git pack-refs --all\n \n \n-qgit --all master\n+gitk --all master\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..300c0cea48c6c4eda2b870b3631355c2137cebb0\nGIT binary patch\nliteral 1296\nzcmexg;-AdGz`z8=xBw$if)Wfen|Y98R-n6x!E8Wvw8HE_v#E_afM$;3(J&x74Y2LV\nz)Q$1iT(-xv{o%d?ezP~d30WlO{o~}bSuv7YXEk0%y}!Bi+NY5F;<3>Ud#7h~`1YT>\nzpf~%nNr$-eG+Xt8#O{s4dXa}k?k(2XVRih3k&*4s=J(gu+%LX=d`sY>$NY6y^vccL\nzFK5=6yT6d|<2_P&W-sI8NG8+rIE_yi-_5-HB{Hf?{<GXKDS;Zn=f$-%{*{*K-dyoz\nz&(nux&wt#UJNGfeC6_5O>cO{}3Ii^?mL8a&y=G5Sv+Zu7cmBCoC&;S-%NRy4AT9!?\nz`vpMy1+YjH0J3?2>?R=nM4az|fajV^sv(TevSnRfJoL#bbLi`ut*5^~(=3sT{r8l`\nLdIkBjci#j6ga?3q\n\nliteral 0\nHcmV?d00001\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..fca3460ed2d263db153ef11a3e559aa47be9efa1\nGIT binary patch\nliteral 562\nzcmWG=boORoU|<4bj+wj_bLMu(avd@dV7p)3wYNd_w#iMsjvLl57%x5H=K9t?sp<Ik\nzy-ohcJU(|Bgw!K{Gkv_Y)iV2yx4Bxy1{RN(o3pO*q+i>SxK8BLij_wrj#O`T2rS%|\nzUidH}#Dz~P_m$6`*V#8S7O30$?L3y2f3D=Xx!-Gc->7BMhQ+Jj+_2mgvGJNrY1Q>E\nz`!M4(EkS4a)5PtqUNAR^RLt3ZvSM!F_9Ysop$AQ_o=`fgan!){>Lnvp)w4&gTr#<6\nzbJ0Ne><t4`-HQenFC4JBdBNan&7yZ)YUX+jzt0Q2UdLK7$Jmg8snw;eQ&#wAvg(}L\nzl3h94ac_R_Q2Cq@G><bvueUMReOX@5{%4zP=e_0sF8g8j-j}{7l$@EFjfI6<?;LqF\nz>59_cNnJv1%X-D5F2%7O*}gP)y~fA+sX;sDEEi;$xJmWcT1KEPCI$w^hJhZ*0-ygC\nze!96v!gK9rDgDLw?#EQU4L(uJFlPtvbn}Wi-e-b6e7zqtF>ux~X%pkRgJF9WHdZg*\nz5cec;Vs*D^S%j>8VoFLzLPA>7q6xDjVkSi`2@eW9bYaU!C+}OQ8-8rt@>W#!-)0}K\nz>7PxQ7@WVWFrc_@!{3{K{@t4O`{?)ne9o9JGxophirXp4u;mKxJX5gi3V?27nZf8F\nZ&i6pTbIm2y5XNWOvMw(k`ec<k001O50^|Sy\n\nliteral 0\nHcmV?d00001\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx\nindex cf58d5baa11824217bb0c5eab7444fb406219885..58b712f6c58e3b99abd536c17c306ef2c37c5238 100644\nGIT binary patch\ndelta 89\nzcmV-f0H*)I2+Rlw|8!4d00002kpW(@UZMj;7j}SvqA`rvo4QPkhl4}`;t5v+%)Fm1\nv0000CGYgnnQ2?6FEimT$X76fU(jBSR$3y!oeS1unZtru#oQ%-R@OV6B4p%0y\n\nliteral 1088\nzcmZQzpebMknm&q0!(cQG4Bj-rBVN|fu*k6I#_U}_-R;dTjE^|OnT@$;L<KU;I;(5&\nj?04Gxtk_GkE3duSzFw<E`CW}`!gtH2lI+N+ZF^b)CtDqp\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx\nindex 2579301b8447e4d55480f65ae6c27fe1eb99bf4d..3ff542377406158d8155129ae66fc0b51cba76b8 100644\nGIT binary patch\ndelta 1975\nzcmWNSc{~(o9L8VczD?s85wmDmCU<REE7_%?a(yIa3Nhujj!cFI!x(prt4tc2lCznL\nz1~tkN*3sk&Z76pK<xDp1`^WqFywCG~f6x28f4y`imWssBXy*$600c{ff@n4!@-K4*\nzh&E+cMsP%Ib<EEyNg~_)<6Z=z@v&lR&4t^o{5zON$(63T8`MI*TJpp#7UthPAzfOc\nzlyz+6vCLqF@J2mU$LOeTUUpuRf{5UCEp}(q*rmd}hnHb5?x{MYFmbx@5(WhVT^1(X\nzog&=aI9Bs}ggMsT%6*iUi?KF(51%v80Z!80O5c~}T}7;?f9zY{pjX?po{6)4p}hSG\nzlzCk0IJh3wY`JgCbeOr=uK9Z8%1+SCZoz?POdQGFPH=ox19Pu#;j#r@gY}e1-X<*8\nztg+3zu`%e}u|U$ulM|81z|3FJ^;VmwapsJJkGG1&aa+H3thG=i6+bmj_TbvrmCoc$\nzc-yFT6Q)bDggm<Y)Qu}Sk;Arc{@X<mxt;$l9oOn`m^eDS&^agm4)w8xB*YDNdr2e5\nzzr&jva1$*1^6a;>iUlNBQ@xh8XZX%<u1CTWMR>|Q75Q-VjND>ulSg@_&y*95g(;{K\nznYx3VYzXiYJx$@;d$o8X3qJqlCvZA=6Z=cJTbNfw5c28!rt}-S^usHds;jwag@fn!\nzS8qfuunGdNq*dwi%%<rm`)D7`ZQjV}p*eitQyKU7m+ezpO!oV6y>Cu*yRWo>jXdr3\nz6wX<(v4{SC3u6eoBJPRHuJ1n~-?w~;6YU70RtZ?l`BxOJe3O$y<L@@*EOt2|nJBV)\nzfUb#Gd^$1LmP{*L&3+x))b?@9<J$6el!VHmD5<jYKvqYXVhkqC6DdEi-lUDO3(+Wv\nzysbq^*0ZSCE%sTX^|tid<ah2SO>QO4`c1`0C!9^A-bc4mTX$Bn+nyvFuTzbuMG0ln\nzofVa_Xv*eWh7K>8D@Y+OxtymFACsb;Z<zmGDU+1EV@QgMDUI$>z_6s6KQMpGh*P2x\nz%27#^OUM6a+4}cayIYGz&CXG&j&VP#_wMmIm3ncr?ixZkebb*h_{C1Gzo+d7PKBqZ\nzXf?m=%uh@WYm=xCsjJ<8_qDSs*Wf{%&aMs(OYt`2mKrRmy(MQgoz`BBwidoe8+g%>\nzkobcw40dFRR|4*|w|g382N~&qdC(MYDm!Y_IGz_ih))>Lb!k=_X1FK){^C8N1mI*<\nzI91De^gMY2+U__m!<w|n|H=;R^b0F;_eB{RDW%8X8tu~MH^dlwwr3P&IE7SadfZK<\nzluYB#KP`)?6rB5BK_Be<V`0qbm|;XcIsEe@mc?7i+m@1Q@!3n6mimLMn)DB}wZhkF\nz?CCk#*}&Q`qbb8hw8X0W$m86h+N)Rpd`>^N<Dfs{NHR?zwsw44sTF9+i*3!martnz\nz;^>#D&%cs&@7FU#JcGj8ZA-P)4464)EJ}Fs_D)k8g}UC>EMq;kV-$Q|gjM}DwV=5%\nz_}I5Yp9^KKqfTxT?ZP>6k}Q7dUuITBA*)ICD8-dd`I_;E%+O~Mby*TAGD*r4w6g~S\nzyexy8`t_fa%a#N#nxE>vw>QeLQ@PFre#!G>iugOlHc^LvgCdJg(<9gojkul{_bC+8\nz69>F(>mSLu)wQ-0PS<?<onE#j+{Fc_$SwfBx=-c&b+<bLq$97^G`Pli=B_8pB8Jpi\nzexE+1dB$g0Y|%t;idVb;@Q9Lv%z@S6Caz{T2wLNKuRiisi2WQ?nk7CKq+eIDvCy~q\nz6`k1HRCDBH2Hk%`K4*Myu93VLnPN4C#S*;PS>JH8KcypkB@5ncRZU=}KH96_q#HEM\nzxBm3rCok9UqU83-QUf&xGM<>MR`)V4C58qdSe8{266V7V(zoQctO_q`ni7>qgY|c;\nzruth3kkWtR1%_Q7n&w~us~__9)|NEra+0;p|EDD5x~h#dgPA>b>D4-#;)Gq>2)Om;\nzC2i5-Qs|itym7H^$-c$DtN9JvzN+O$Twg0&`nQv2$@&Auk>uq*xAD!f@qcim;RdFh\nzLfeAS+><K!IQJf5?d=N<HM@@Ka>ZdA*u*!ZgK}+DCT0ksb@vC2=f<9yy(gNkYH3K)\nzOziCCA8z3FEF;fH4z4*<GzffNE?M|!j(WY9r%R>R)XPK68OCKk!$nlyoMV??=#U*P\nzd1l{D@BH-~wiLU_;hu2WOsS4@L5+XRsR#3Vt1mefM%%CO+Doafhws1rdP-CkQ&T<|\nzc5i-n?*k?xbdKrk^XwQwPSfH68UVRT0Hn+SP`UzutS(#>4m8E#SF{O5J^%{-P@e-p\nzSrhKn0g${7z@AX3O8^k1z&}d{o-4xzJ!!~`F#%9K0_`dQkj?;z%){^@s0{&-2!y$Z\nzAR_`96!f3Lxp<iO9J0}n#R5PPAApBh@UjS4;2VT+0HAyUkS9Q04*gLG>%$>fQgIBn\nzhYS+>NDat!0U(?M**mb<M_95O&SRkO0WX5(glYf~KM1ufe25Utqd_JFW;MW>$FQ8#\ntIo)0Ce0{H4d`WoglAGiPUdBsD(Nnqf$%y01fxIk6k#j3%Ow8X>?tj#hbMOEF\n\ndelta 1424\nzcmXAodpOg39LK-zhS}CORBqiywTvYvt=owdD#N2mgzBt@5IKe;vS>-U{M=6D3@eXI\nzwN+-U$n|h4?YM<bxg?b9L8d%7UpxPPp6C1ezTfZ9=grgQ67$uSEdjtNDOOS2&*wP<\nz#X22l#6LK^By6P^01bB(lW#e;PSHzLL5MFsS6EYh-&h0yQGl2$6OI9ZKBloRJmlyt\nze{7J*6yMO*Ws-V3^%|UaVwI)u%1Ddz=JW!~7IC7T8e?rc0NP}1uY1NtV?1EdM|xcy\nzgI!z%v|#|0)+4e111pF>z6?7n@9SSOnEb{qIZ)#f`EwHh*c_ej;~>xNV#BVv(5gKK\nzGHOTeXgvgSjNWxdEc$&~PT%n|m&~@bksg~d1VHB`B9#NNuB0%%<Zc$b^ZD@*9P8Ew\nzy+^cpcK}e;WJ_dMg)B>rEZf>JD?t&)MIT!LSi>jR&k;TD^m-mx-|W?&ouuH_{8}FZ\nz-y+5;tCm&xhlWNPKdTMk$0Te8p}))9gs9&J003I{)a}CPJ+D*kz9(f#+0Il`$?Qw0\nzkY?Yw;CwJJR#~hg*2M(rebOEcuY~h7Bv=mAtZ=WkJ0)S@(kBj|l{)UaN7@kN5(t25\nz?Wtft+>61=n|DpPyQhqcuO{EfXaj%{?!BetTj&TcofUDT*hIXupNqG<0{?GCUdn;E\nzgtJ1=d%exBQxfnkb<^B+!D-d*r%<`(`LiS4iZ+?T<G(r&j^hR;(~&9-(3(a7r&!9%\nz9sYY`n#GCso`HF7>tz81x*}NBRm<vkE>+fz$=p&VzlW;pT7_!l<+FJ3q2lR4LYQ$N\nz1BYpytK4L46JVGfQn(Q+-x?EVYF)6L<ujY`O7iMJTI2Gyk20v-0r8OoiLyBJIgWY1\nzidUXyV?j~4-uwq-vlwQQA19PvXMUl3Con76SDfxzUM|vt=d@-aZqbY#8kTdV0c*_D\nzsQQ}wQ(`0$09+{|kOP$+IUI+`rIK}Pd``w+n17g}sC0AwJOFC5oVID3^>140mdLtd\nzQvz*x(y2NYDyfeTtW$p!@UU#lgLh7Ah1;J*ZeHFD&#Wj-ZPl^1K|*U&d35X&UkNOt\nznGwI-udioN;NhRU?MK-*{iHI8iteI_dQyYh?4x@Cz-K4ZtB4(l>$Sa2gNoUJjMfzt\nzPr_owA#^zq-IVF-i#MYXZ~pd2*PkZU<zeQG`b6jeotfwuP;$%dL2P!vz4wc}up;T1\nzA8_tlz-@cIf25mo)GYW>RM5mTp7jS5OkzL6lLLtue*b6m5UVVZ(q}fRr#|D_S&<AI\nzrfE=i^{Q<x_srsvZJiEmYBaN^VSEY#yUU~-F{-km_w=u)3l2^9O>B)ac?{=n$g~`Y\nzU#`3n!<nnA(%RR(Nb&bp=9T;#pAM_}v`XZEbiryOL+f|^iFu|?kRTGpgVz44&N;l3\nz##Eqv)DI<0HDXG8p5|VHJs3j{s;_3Kvr-$C_eDxK8h`ksUZlm37dm-WXTuB`wQ(_O\nz1B5!2Bmek?WV&;M`Q;)q%rL2?>2VDE`4M|`&Hgy@%xv9p#}r?<iwYz~4pb<W;vB?f\nzRR2=*PY)P8>o9g>{$nm&vPZj-hfjy<sD<>TxNOVrP9j!o#|#A8c2o+Dnt|V}z;ouA\nzFE)I_FDFS2R-c6Q%Yo?9Ud)}Ib;%TrY80)HMDp_FCoMoFI)y_knjx=H>F;I5y(En>\nzJN<jy?d351@!^^kPXmnh8#>YD*&aiDH%NSL0i&2i%u$4cun_t(TE+z<DpRM+f7>Fh\nz?~SAtr)g`O&$8&1U0h1vT~cU;GC=Re9<sOUyT0Rzlyn)1V7VEdU<8k4y$JXZTkul8\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack\nindex bb47c90d93b0b2276fc36b96bc8734085bde6007..ef56d7e941828561e9f6e2cbc46e2d6c9c8d76bf 100644\nGIT binary patch\ndelta 55\nzcmV-70LcHuE{!g*s{sV$1%N=4!2w$X;R0W?G6I+l180Cov)>O<2NYiZCg!fo8+@2=\nNzv)s5^+^m_Both>71IC!\n\ndelta 110\nzcmV-!0FnQVF2pXds{t1D1;B8vj0l7bffm|^TP<Z-I%~PjDwD4PTNd#G&=E?wtTJn>\nzFyp3IpgDDT#i6f=vkd~64Hb6+x-!#bo>2e-!WL1JYjAg}b^oces1H#G6hxtEG1~WN\nQ{ggPWqc#a04LlG+NkNq^UjP6A\n\ndiff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs\nindex 746bd6b..38a70ec 100644\n--- a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs\n+++ b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs\n@@ -4,8 +4,10 @@\n 6e1475206e57110fcef4b92320436c1e9872a322 refs/heads/c\n f73b95671f326616d66b2afb3bdfcdbbce110b44 refs/heads/d\n d0114ab8ac326bab30e3a657a0397578c5a1af88 refs/heads/e\n-d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864 refs/heads/pa\n+47d3697c3747e8184e0dc479ccbd01e359023577 refs/heads/f\n+175d5b80bd9768884d8fced02e9bd33488174396 refs/heads/g\n 49322bb17d3acc9146f98c97d078513228bbf3c0 refs/heads/master\n+d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864 refs/heads/pa\n 6db9c2ebf75590eef973081736730a9ea169a0c4 refs/tags/A\n 17768080a2318cd89bba4c8b87834401e2095703 refs/tags/B\n ^d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\nindex 9e48fde..20348f1 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\n@@ -236,7 +236,8 @@ public void run() {\n \t\t\t\t\"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371\",\n \t\t\t\t\"pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745\",\n \t\t\t\t\"pack-546ff360fe3488adb20860ce3436a2d6373d2796\",\n-\t\t\t\t\"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa\"\n+\t\t\t\t\"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa\",\n+\t\t\t\t\"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12\"\n \t\t};\n \t\tfinal File packDir = new File(db.getObjectsDirectory(), \"pack\");\n \t\tfor (int k = 0; k < packs.length; k++) {\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java\nnew file mode 100644\nindex 0000000..96064f5\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java\n@@ -0,0 +1,86 @@\n+/*\n+ * Copyright (C) 2008, Robin Rosenberg\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.merge;\n+\n+import java.io.IOException;\n+\n+import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.RepositoryTestCase;\n+\n+public class SimpleMergeTest extends RepositoryTestCase {\n+\n+\tpublic void testOurs() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.OURS.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"a\"), db.resolve(\"c\") });\n+\t\tassertTrue(merge);\n+\t\tassertEquals(db.mapTree(\"a\").getId(), ourMerger.getResultTreeId());\n+\t}\n+\n+\tpublic void testTheirs() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.THEIRS.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"a\"), db.resolve(\"c\") });\n+\t\tassertTrue(merge);\n+\t\tassertEquals(db.mapTree(\"c\").getId(), ourMerger.getResultTreeId());\n+\t}\n+\n+\tpublic void testTrivialTwoWay() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"a\"), db.resolve(\"c\") });\n+\t\tassertTrue(merge);\n+\t\tassertEquals(\"02ba32d3649e510002c21651936b7077aa75ffa9\",ourMerger.getResultTreeId().name());\n+\t}\n+\n+\tpublic void testTrivialTwoWay_disjointhistories() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"a\"), db.resolve(\"c~4\") });\n+\t\tassertTrue(merge);\n+\t\tassertEquals(\"86265c33b19b2be71bdd7b8cb95823f2743d03a8\",ourMerger.getResultTreeId().name());\n+\t}\n+\n+\tpublic void testTrivialTwoWay_ok() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"a^0^0^0\"), db.resolve(\"a^0^0^1\") });\n+\t\tassertTrue(merge);\n+\t\tassertEquals(db.mapTree(\"a^0^0\").getId(), ourMerger.getResultTreeId());\n+\t}\n+\n+\tpublic void testTrivialTwoWay_conflict() throws IOException {\n+\t\tMerger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);\n+\t\tboolean merge = ourMerger.merge(new ObjectId[] { db.resolve(\"f\"), db.resolve(\"g\") });\n+\t\tassertFalse(merge);\n+\t}\n+}\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java\nindex dc1cb21..c6e3335 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java\n@@ -123,7 +123,7 @@ public void testFindRemoteRefUpdatesWildcardNoTracking() throws IOException {\n \t\t\t\t.findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(\n \t\t\t\t\t\t\"+refs/heads/*:refs/heads/test/*\")));\n \n-\t\tassertEquals(7, result.size());\n+\t\tassertEquals(9, result.size());\n \t\tboolean foundA = false;\n \t\tboolean foundB = false;\n \t\tfor (final RemoteRefUpdate rru : result) {\n-- \n1.6.1.399.g0d272\n"},{"id":"101695","messageId":"200901232242.15073.robin.rosenberg.lists@dewire.com","threadId":"17310","inReplyTo":"1232666890-23488-3-git-send-email-spearce@spearce.org","subject":"Re: [JGIT PATCH 02/10] Expose the raw path for the current entry of a TreeWalk","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2009-01-23T21:42:14Z","receivedAt":"2009-01-23T21:42:14Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredag 23 januari 2009 00:28:02 skrev Shawn O. Pearce:\n> Copying the path byte array (keeping it encoded in UTF-8) is quicker\n> than converting to String and then back again to UTF-8 when creating\n> a DirCacheEntry for the current position in a TreeWalk.\n[...]\n> +\t * Get the current entry's complete path as a UTF-8 byte array.\n/Hopefully/ UTF-8. It is often a legacy encoding, like ISO-8859-X, CP12xx\netc. I'll come up with something less specific that just UTF-8.\n\n-- robin\n"}]}