{"thread":{"id":"1793","subject":"[PATCH 0/5] More recursive merge updates","startedAt":"2005-09-13T21:37:30Z","lastAt":"2005-09-13T21:41:39Z","messageCount":6,"participants":["Fredrik Kuivinen"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"8483","messageId":"20050913213730.GA10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":null,"subject":"[PATCH 0/5] More recursive merge updates","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:37:30Z","receivedAt":"2005-09-13T21:37:30Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"Here is another patch series with updates to the recursive merge\nalgorithm.\n\n- Fredrik\n"},{"id":"8484","messageId":"20050913213934.GB10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":"20050913213730.GA10953@c165.ib.student.liu.se","subject":"[PATCH 1/5] Be more like the 'resolve' strategy.","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:39:34Z","receivedAt":"2005-09-13T21:39:34Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"If there are non-mergeable changes leave the head contents in the\ncache and update the working directory with the output from merge(1).\n\nIn the add/add and delete/modify conflict cases leave unmerged cache\nentries in the index.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n git-merge-recursive.py |   68 +++++++++++++++++++++++-------------------------\n 1 files changed, 33 insertions(+), 35 deletions(-)\n\n11a6300badeb3b2a46d088877f2f264d18b2160d\ndiff --git a/git-merge-recursive.py b/git-merge-recursive.py\n--- a/git-merge-recursive.py\n+++ b/git-merge-recursive.py\n@@ -7,8 +7,6 @@ from sets import Set\n sys.path.append('@@GIT_PYTHON_PATH@@')\n from gitMergeCommon import *\n \n-alwaysWriteTree = False\n-\n # The actual merge code\n # ---------------------\n \n@@ -46,19 +44,14 @@ def merge(h1, h2, branch1Name, branch2Na\n             runProgram(['git-update-cache', '-q', '--refresh'])\n         # Use the original index if we only have one common ancestor\n         \n-        updateWd = True\n-        if alwaysWriteTree:\n-            cleanCache = True\n-        else:\n-            cleanCache = False\n+        cleanCache = False\n     else:\n         runProgram(['git-read-tree', h1.tree()])\n-        updateWd = False\n         cleanCache = True\n \n     [shaRes, clean] = mergeTrees(h1.tree(), h2.tree(), Ms.tree(),\n                                  branch1Name, branch2Name,\n-                                 cleanCache, updateWd)\n+                                 cleanCache)\n \n     if clean or cleanCache:\n         res = Commit(None, [h1, h2], tree=shaRes)\n@@ -125,7 +118,7 @@ def unmergedCacheEntries():\n     return res\n \n def mergeTrees(head, merge, common, branch1Name, branch2Name,\n-               cleanCache, updateWd):\n+               cleanCache):\n     '''Merge the trees 'head' and 'merge' with the common ancestor\n     'common'. The name of the head branch is 'branch1Name' and the name of\n     the merge branch is 'branch2Name'. Return a tuple (tree, cleanMerge)\n@@ -138,10 +131,11 @@ def mergeTrees(head, merge, common, bran\n         print 'Already uptodate!'\n         return [head, True]\n \n-    if updateWd:\n-        updateArg = '-u'\n-    else:\n+    if cleanCache:\n         updateArg = '-i'\n+    else:\n+        updateArg = '-u'\n+\n     runProgram(['git-read-tree', updateArg, '-m', common, head, merge])\n     cleanMerge = True\n \n@@ -157,7 +151,7 @@ def mergeTrees(head, merge, common, bran\n         entries = unmergedCacheEntries()\n         for name in entries:\n             if not processEntry(entries[name], branch1Name, branch2Name,\n-                                files, dirs, cleanCache, updateWd):\n+                                files, dirs, cleanCache):\n                 cleanMerge = False\n                 \n         if cleanMerge or cleanCache:\n@@ -169,29 +163,25 @@ def mergeTrees(head, merge, common, bran\n \n     return [tree, cleanMerge]\n \n-def processEntry(entry, branch1Name, branch2Name, files, dirs,\n-                 cleanCache, updateWd):\n+def processEntry(entry, branch1Name, branch2Name, files, dirs, cleanCache):\n     '''Merge one cache entry. 'files' is a Set with the files in both of\n     the heads that we are going to merge. 'dirs' contains the\n     corresponding data for directories. If 'cleanCache' is True no\n     non-zero stages will be left in the cache for the path\n     corresponding to the entry 'entry'.'''\n \n-# cleanCache == True  => Don't leave any non-stage 0 entries in the cache.\n-#               False => Leave unmerged entries\n-\n-# updateWd  == True  => Update the working directory to correspond to the cache\n-#              False => Leave the working directory unchanged\n+# cleanCache == True  => Don't leave any non-stage 0 entries in the cache and\n+#                        don't update the working directory\n+#               False => Leave unmerged entries and update the working directory\n \n # clean     == True  => non-conflict case\n #              False => conflict case\n \n # If cleanCache == False then the cache shouldn't be updated if clean == False\n \n-    def updateFile(clean, sha, mode, path):\n-        if cleanCache or (not cleanCache and clean):\n-            runProgram(['git-update-cache', '--add', '--cacheinfo',\n-                        '0%o' % mode, sha, path])\n+    def updateFile(clean, sha, mode, path, onlyWd=False):\n+        updateCache = not onlyWd and (cleanCache or (not cleanCache and clean))\n+        updateWd = onlyWd or (not cleanCache and clean)\n \n         if updateWd:\n             prog = ['git-cat-file', 'blob', sha]\n@@ -213,13 +203,18 @@ def processEntry(entry, branch1Name, bra\n                 os.symlink(linkTarget, path)\n             else:\n                 assert(False)\n-            runProgram(['git-update-cache', '--', path])\n+\n+        if updateWd and updateCache:\n+            runProgram(['git-update-cache', '--add', '--', path])\n+        elif updateCache:\n+            runProgram(['git-update-cache', '--add', '--cacheinfo',\n+                        '0%o' % mode, sha, path])\n \n     def removeFile(clean, path):\n         if cleanCache or (not cleanCache and clean):\n             runProgram(['git-update-cache', '--force-remove', '--', path])\n \n-        if updateWd:\n+        if not cleanCache and clean:\n             try:\n                 os.unlink(path)\n             except OSError, e:\n@@ -235,8 +230,7 @@ def processEntry(entry, branch1Name, bra\n         files.add(newPath)\n         return newPath\n \n-    debug('processing', entry.path, 'clean cache:', cleanCache,\n-          'wd:', updateWd)\n+    debug('processing', entry.path, 'clean cache:', cleanCache)\n \n     cleanMerge = True\n \n@@ -327,9 +321,9 @@ def processEntry(entry, branch1Name, bra\n             if aMode != bMode:\n                 cleanMerge = False\n                 print 'CONFLICT: File \"' + path + \\\n-                      '\" added identically in both branches,'\n-                print 'CONFLICT: but permissions conflict', '0%o' % aMode, \\\n-                      '->', '0%o' % bMode\n+                      '\" added identically in both branches,', \\\n+                      'but permissions conflict', '0%o' % aMode, '->', \\\n+                      '0%o' % bMode\n                 print 'CONFLICT: adding with permission:', '0%o' % aMode\n \n                 updateFile(False, aSha, aMode, path)\n@@ -341,8 +335,7 @@ def processEntry(entry, branch1Name, bra\n             newPath1 = uniquePath(path, branch1Name)\n             newPath2 = uniquePath(path, branch2Name)\n             print 'CONFLICT (add/add): File \"' + path + \\\n-                  '\" added non-identically in both branches.', \\\n-                  'Adding \"' + newPath1 + '\" and \"' + newPath2 + '\" instead.'\n+                  '\" added non-identically in both branches.'\n             removeFile(False, path)\n             updateFile(False, aSha, aMode, newPath1)\n             updateFile(False, bSha, bMode, newPath2)\n@@ -372,7 +365,12 @@ def processEntry(entry, branch1Name, bra\n         if ret != 0:\n             cleanMerge = False\n             print 'CONFLICT (content): Merge conflict in \"' + path + '\".'\n-            updateFile(False, sha, mode, path)\n+\n+            if cleanCache:\n+                updateFile(False, sha, mode, path)\n+            else:\n+                updateFile(True, aSha, aMode, path)\n+                updateFile(False, sha, mode, path, True)\n         else:\n             updateFile(True, sha, mode, path)\n \n"},{"id":"8488","messageId":"20050913214023.GC10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":"20050913213730.GA10953@c165.ib.student.liu.se","subject":"[PATCH 2/5] Don't output 'Automatic merge failed, ...'","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:40:23Z","receivedAt":"2005-09-13T21:40:23Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"git-merge.sh does this for us.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n git-merge-recursive.py |    1 -\n 1 files changed, 0 insertions(+), 1 deletions(-)\n\ne0e1a108a224b6bf202beb59c1514325205d3638\ndiff --git a/git-merge-recursive.py b/git-merge-recursive.py\n--- a/git-merge-recursive.py\n+++ b/git-merge-recursive.py\n@@ -423,5 +423,4 @@ except:\n if clean:\n     sys.exit(0)\n else:\n-    print 'Automatic merge failed, fix up by hand'\n     sys.exit(1)\n"},{"id":"8487","messageId":"20050913214047.GD10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":"20050913213730.GA10953@c165.ib.student.liu.se","subject":"[PATCH 3/5] Adjust git-merge-recursive.py for the new tool names.","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:40:47Z","receivedAt":"2005-09-13T21:40:47Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n git-merge-recursive.py |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\nc8d10db0a5380fc52681255b78433390b357c4d0\ndiff --git a/git-merge-recursive.py b/git-merge-recursive.py\n--- a/git-merge-recursive.py\n+++ b/git-merge-recursive.py\n@@ -41,7 +41,7 @@ def merge(h1, h2, branch1Name, branch2Na\n     if callDepth == 0:\n         if len(ca) > 1:\n             runProgram(['git-read-tree', h1.tree()])\n-            runProgram(['git-update-cache', '-q', '--refresh'])\n+            runProgram(['git-update-index', '-q', '--refresh'])\n         # Use the original index if we only have one common ancestor\n         \n         cleanCache = False\n@@ -205,14 +205,14 @@ def processEntry(entry, branch1Name, bra\n                 assert(False)\n \n         if updateWd and updateCache:\n-            runProgram(['git-update-cache', '--add', '--', path])\n+            runProgram(['git-update-index', '--add', '--', path])\n         elif updateCache:\n-            runProgram(['git-update-cache', '--add', '--cacheinfo',\n+            runProgram(['git-update-index', '--add', '--cacheinfo',\n                         '0%o' % mode, sha, path])\n \n     def removeFile(clean, path):\n         if cleanCache or (not cleanCache and clean):\n-            runProgram(['git-update-cache', '--force-remove', '--', path])\n+            runProgram(['git-update-index', '--force-remove', '--', path])\n \n         if not cleanCache and clean:\n             try:\n"},{"id":"8486","messageId":"20050913214116.GE10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":"20050913213730.GA10953@c165.ib.student.liu.se","subject":"[PATCH 4/5] Use a temporary index file when we merge the common ancestors.","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:41:16Z","receivedAt":"2005-09-13T21:41:16Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"With this change we can get rid of a call to 'git-update-index\n--refresh'.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n git-merge-recursive.py |   23 ++++++++++++++++++-----\n 1 files changed, 18 insertions(+), 5 deletions(-)\n\n68a73c83a0ba2175cb366bddf3b851f824c6d598\ndiff --git a/git-merge-recursive.py b/git-merge-recursive.py\n--- a/git-merge-recursive.py\n+++ b/git-merge-recursive.py\n@@ -10,6 +10,22 @@ from gitMergeCommon import *\n # The actual merge code\n # ---------------------\n \n+originalIndexFile = os.environ.get('GIT_INDEX_FILE',\n+                                   os.environ.get('GIT_DIR', '.git') + '/index')\n+temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \\\n+                     '/merge-recursive-tmp-index'\n+def setupIndex(temporary):\n+    try:\n+        os.unlink(temporaryIndexFile)\n+    except OSError:\n+        pass\n+    if temporary:\n+        newIndex = temporaryIndexFile\n+        os.environ\n+    else:\n+        newIndex = originalIndexFile\n+    os.environ['GIT_INDEX_FILE'] = newIndex\n+\n def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):\n     '''Merge the commits h1 and h2, return the resulting virtual\n     commit object and a flag indicating the cleaness of the merge.'''\n@@ -39,13 +55,10 @@ def merge(h1, h2, branch1Name, branch2Na\n         assert(isinstance(Ms, Commit))\n \n     if callDepth == 0:\n-        if len(ca) > 1:\n-            runProgram(['git-read-tree', h1.tree()])\n-            runProgram(['git-update-index', '-q', '--refresh'])\n-        # Use the original index if we only have one common ancestor\n-        \n+        setupIndex(False)\n         cleanCache = False\n     else:\n+        setupIndex(True)\n         runProgram(['git-read-tree', h1.tree()])\n         cleanCache = True\n \n"},{"id":"8489","messageId":"20050913214139.GF10953@c165.ib.student.liu.se","threadId":"1793","inReplyTo":"20050913213730.GA10953@c165.ib.student.liu.se","subject":"[PATCH 5/5] Use the 'die' function where it is appropriate.","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-13T21:41:39Z","receivedAt":"2005-09-13T21:41:39Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n gitMergeCommon.py |   27 +++++++++++++--------------\n 1 files changed, 13 insertions(+), 14 deletions(-)\n\nbd535d629be12d94648a40c2feb89cf14482f772\ndiff --git a/gitMergeCommon.py b/gitMergeCommon.py\n--- a/gitMergeCommon.py\n+++ b/gitMergeCommon.py\n@@ -1,19 +1,24 @@\n import sys, re, os, traceback\n from sets import Set\n \n+def die(*args):\n+    printList(args, sys.stderr)\n+    sys.exit(2)\n+\n+def printList(list, file=sys.stdout):\n+    for x in list:\n+        file.write(str(x))\n+        file.write(' ')\n+    file.write('\\n')\n+\n if sys.version_info[0] < 2 or \\\n        (sys.version_info[0] == 2 and sys.version_info[1] < 4):\n-    print 'Python version 2.4 required, found', \\\n-          str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \\\n-          str(sys.version_info[2])\n-    sys.exit(1)\n+    die('Python version 2.4 required, found', \\\n+        str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \\\n+        str(sys.version_info[2]))\n \n import subprocess\n \n-def die(*args):\n-    printList(args, sys.stderr)\n-    sys.exit(2)\n-\n # Debugging machinery\n # -------------------\n \n@@ -32,12 +37,6 @@ def debug(*args):\n         if funcName in functionsToDebug:\n             printList(args)\n \n-def printList(list, file=sys.stdout):\n-    for x in list:\n-        file.write(str(x))\n-        file.write(' ')\n-    file.write('\\n')\n-\n # Program execution\n # -----------------\n \n"}]}