{"thread":{"id":"2461","subject":"[PATCH 1/3] merge-recursive: Indent the output properly","startedAt":"2005-11-11T23:53:07Z","lastAt":"2005-11-11T23:53:07Z","messageCount":1,"participants":["Fredrik Kuivinen"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"11638","messageId":"20051111235306.GA9757@c165.ib.student.liu.se","threadId":"2461","inReplyTo":null,"subject":"[PATCH 1/3] merge-recursive: Indent the output properly","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-11-11T23:53:07Z","receivedAt":"2005-11-11T23:53:07Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"If we have multiple common ancestors and have to recursively merge\nthem then the output will be much more readable with this commit.\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n\n\n---\n\n git-merge-recursive.py |  132 +++++++++++++++++++++++++-----------------------\n 1 files changed, 70 insertions(+), 62 deletions(-)\n\napplies-to: 61d3c7b885a193afa970b5dd319d5264dcbd11ad\n66f3f641939645d4f26849adfdc54f4f00cb72f1\ndiff --git a/git-merge-recursive.py b/git-merge-recursive.py\nindex 90e889c..e6cbdde 100755\n--- a/git-merge-recursive.py\n+++ b/git-merge-recursive.py\n@@ -7,6 +7,11 @@ from sets import Set\n sys.path.append('''@@GIT_PYTHON_PATH@@''')\n from gitMergeCommon import *\n \n+outputIndent = 0\n+def output(*args):\n+    sys.stdout.write('  '*outputIndent)\n+    printList(args)\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@@ -41,27 +46,27 @@ def merge(h1, h2, branch1Name, branch2Na\n     assert(isinstance(h1, Commit) and isinstance(h2, Commit))\n     assert(isinstance(graph, Graph))\n \n-    def infoMsg(*args):\n-        sys.stdout.write('  '*callDepth)\n-        printList(args)\n-\n-    infoMsg('Merging:')\n-    infoMsg(h1)\n-    infoMsg(h2)\n+    global outputIndent\n+\n+    output('Merging:')\n+    output(h1)\n+    output(h2)\n     sys.stdout.flush()\n \n     ca = getCommonAncestors(graph, h1, h2)\n-    infoMsg('found', len(ca), 'common ancestor(s):')\n+    output('found', len(ca), 'common ancestor(s):')\n     for x in ca:\n-        infoMsg(x)\n+        output(x)\n     sys.stdout.flush()\n \n     mergedCA = ca[0]\n     for h in ca[1:]:\n+        outputIndent = callDepth+1\n         [mergedCA, dummy] = merge(mergedCA, h,\n-                                  'Temporary shared merge branch 1',\n-                                  'Temporary shared merge branch 2',\n+                                  'Temporary merge branch 1',\n+                                  'Temporary merge branch 2',\n                                   graph, callDepth+1)\n+        outputIndent = callDepth\n         assert(isinstance(mergedCA, Commit))\n \n     global cacheOnly\n@@ -116,7 +121,7 @@ def mergeTrees(head, merge, common, bran\n     assert(isSha(head) and isSha(merge) and isSha(common))\n \n     if common == merge:\n-        print 'Already uptodate!'\n+        output('Already uptodate!')\n         return [head, True]\n \n     if cacheOnly:\n@@ -554,23 +559,24 @@ def processRenames(renamesA, renamesB, b\n             ren2.processed = True\n \n             if ren1.dstName != ren2.dstName:\n-                print 'CONFLICT (rename/rename): Rename', \\\n-                      fmtRename(path, ren1.dstName), 'in branch', branchName1, \\\n-                      'rename', fmtRename(path, ren2.dstName), 'in', branchName2\n+                output('CONFLICT (rename/rename): Rename',\n+                       fmtRename(path, ren1.dstName), 'in branch', branchName1,\n+                       'rename', fmtRename(path, ren2.dstName), 'in',\n+                       branchName2)\n                 cleanMerge = False\n \n                 if ren1.dstName in currentDirectorySet:\n                     dstName1 = uniquePath(ren1.dstName, branchName1)\n-                    print ren1.dstName, 'is a directory in', branchName2, \\\n-                          'adding as', dstName1, 'instead.'\n+                    output(ren1.dstName, 'is a directory in', branchName2,\n+                           'adding as', dstName1, 'instead.')\n                     removeFile(False, ren1.dstName)\n                 else:\n                     dstName1 = ren1.dstName\n \n                 if ren2.dstName in currentDirectorySet:\n                     dstName2 = uniquePath(ren2.dstName, branchName2)\n-                    print ren2.dstName, 'is a directory in', branchName1, \\\n-                          'adding as', dstName2, 'instead.'\n+                    output(ren2.dstName, 'is a directory in', branchName1,\n+                           'adding as', dstName2, 'instead.')\n                     removeFile(False, ren2.dstName)\n                 else:\n                     dstName2 = ren1.dstName\n@@ -585,13 +591,14 @@ def processRenames(renamesA, renamesB, b\n                                    branchName1, branchName2)\n \n                 if merge or not clean:\n-                    print 'Renaming', fmtRename(path, ren1.dstName)\n+                    output('Renaming', fmtRename(path, ren1.dstName))\n \n                 if merge:\n-                    print 'Auto-merging', ren1.dstName\n+                    output('Auto-merging', ren1.dstName)\n \n                 if not clean:\n-                    print 'CONFLICT (content): merge conflict in', ren1.dstName\n+                    output('CONFLICT (content): merge conflict in',\n+                           ren1.dstName)\n                     cleanMerge = False\n \n                     if not cacheOnly:\n@@ -615,25 +622,25 @@ def processRenames(renamesA, renamesB, b\n             \n             if ren1.dstName in currentDirectorySet:\n                 newPath = uniquePath(ren1.dstName, branchName1)\n-                print 'CONFLICT (rename/directory): Rename', \\\n-                      fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,\\\n-                      'directory', ren1.dstName, 'added in', branchName2\n-                print 'Renaming', ren1.srcName, 'to', newPath, 'instead'\n+                output('CONFLICT (rename/directory): Rename',\n+                       fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,\n+                       'directory', ren1.dstName, 'added in', branchName2)\n+                output('Renaming', ren1.srcName, 'to', newPath, 'instead')\n                 cleanMerge = False\n                 removeFile(False, ren1.dstName)\n                 updateFile(False, ren1.dstSha, ren1.dstMode, newPath)\n             elif srcShaOtherBranch == None:\n-                print 'CONFLICT (rename/delete): Rename', \\\n-                      fmtRename(ren1.srcName, ren1.dstName), 'in', \\\n-                      branchName1, 'and deleted in', branchName2\n+                output('CONFLICT (rename/delete): Rename',\n+                       fmtRename(ren1.srcName, ren1.dstName), 'in',\n+                       branchName1, 'and deleted in', branchName2)\n                 cleanMerge = False\n                 updateFile(False, ren1.dstSha, ren1.dstMode, ren1.dstName)\n             elif dstShaOtherBranch:\n                 newPath = uniquePath(ren1.dstName, branchName2)\n-                print 'CONFLICT (rename/add): Rename', \\\n-                      fmtRename(ren1.srcName, ren1.dstName), 'in', \\\n-                      branchName1 + '.', ren1.dstName, 'added in', branchName2\n-                print 'Adding as', newPath, 'instead'\n+                output('CONFLICT (rename/add): Rename',\n+                       fmtRename(ren1.srcName, ren1.dstName), 'in',\n+                       branchName1 + '.', ren1.dstName, 'added in', branchName2)\n+                output('Adding as', newPath, 'instead')\n                 updateFile(False, dstShaOtherBranch, dstModeOtherBranch, newPath)\n                 cleanMerge = False\n                 tryMerge = True\n@@ -641,12 +648,12 @@ def processRenames(renamesA, renamesB, b\n                 dst2 = renames2.getDst(ren1.dstName)\n                 newPath1 = uniquePath(ren1.dstName, branchName1)\n                 newPath2 = uniquePath(dst2.dstName, branchName2)\n-                print 'CONFLICT (rename/rename): Rename', \\\n-                      fmtRename(ren1.srcName, ren1.dstName), 'in', \\\n-                      branchName1+'. Rename', \\\n-                      fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2\n-                print 'Renaming', ren1.srcName, 'to', newPath1, 'and', \\\n-                      dst2.srcName, 'to', newPath2, 'instead'\n+                output('CONFLICT (rename/rename): Rename',\n+                       fmtRename(ren1.srcName, ren1.dstName), 'in',\n+                       branchName1+'. Rename',\n+                       fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2)\n+                output('Renaming', ren1.srcName, 'to', newPath1, 'and',\n+                       dst2.srcName, 'to', newPath2, 'instead')\n                 removeFile(False, ren1.dstName)\n                 updateFile(False, ren1.dstSha, ren1.dstMode, newPath1)\n                 updateFile(False, dst2.dstSha, dst2.dstMode, newPath2)\n@@ -663,13 +670,14 @@ def processRenames(renamesA, renamesB, b\n                                    branchName1, branchName2)\n \n                 if merge or not clean:\n-                    print 'Renaming', fmtRename(ren1.srcName, ren1.dstName)\n+                    output('Renaming', fmtRename(ren1.srcName, ren1.dstName))\n \n                 if merge:\n-                    print 'Auto-merging', ren1.dstName\n+                    output('Auto-merging', ren1.dstName)\n \n                 if not clean:\n-                    print 'CONFLICT (rename/modify): Merge conflict in', ren1.dstName\n+                    output('CONFLICT (rename/modify): Merge conflict in',\n+                           ren1.dstName)\n                     cleanMerge = False\n \n                     if not cacheOnly:\n@@ -714,21 +722,21 @@ def processEntry(entry, branch1Name, bra\n            (not aSha     and bSha == oSha):\n     # Deleted in both or deleted in one and unchanged in the other\n             if aSha:\n-                print 'Removing', path\n+                output('Removing', path)\n             removeFile(True, path)\n         else:\n     # Deleted in one and changed in the other\n             cleanMerge = False\n             if not aSha:\n-                print 'CONFLICT (delete/modify):', path, 'deleted in', \\\n-                      branch1Name, 'and modified in', branch2Name + '.', \\\n-                      'Version', branch2Name, 'of', path, 'left in tree.'\n+                output('CONFLICT (delete/modify):', path, 'deleted in',\n+                       branch1Name, 'and modified in', branch2Name + '.',\n+                       'Version', branch2Name, 'of', path, 'left in tree.')\n                 mode = bMode\n                 sha = bSha\n             else:\n-                print 'CONFLICT (modify/delete):', path, 'deleted in', \\\n-                      branch2Name, 'and modified in', branch1Name + '.', \\\n-                      'Version', branch1Name, 'of', path, 'left in tree.'\n+                output('CONFLICT (modify/delete):', path, 'deleted in',\n+                       branch2Name, 'and modified in', branch1Name + '.',\n+                       'Version', branch1Name, 'of', path, 'left in tree.')\n                 mode = aMode\n                 sha = aSha\n \n@@ -755,14 +763,14 @@ def processEntry(entry, branch1Name, bra\n         if path in currentDirectorySet:\n             cleanMerge = False\n             newPath = uniquePath(path, addBranch)\n-            print 'CONFLICT (' + conf + '):', \\\n-                  'There is a directory with name', path, 'in', \\\n-                  otherBranch + '. Adding', path, 'as', newPath\n+            output('CONFLICT (' + conf + '):',\n+                   'There is a directory with name', path, 'in',\n+                   otherBranch + '. Adding', path, 'as', newPath)\n \n             removeFile(False, path)\n             updateFile(False, sha, mode, newPath)\n         else:\n-            print 'Adding', path\n+            output('Adding', path)\n             updateFile(True, sha, mode, path)\n     \n     elif not oSha and aSha and bSha:\n@@ -772,10 +780,10 @@ def processEntry(entry, branch1Name, bra\n         if aSha == bSha:\n             if aMode != bMode:\n                 cleanMerge = False\n-                print 'CONFLICT: File', path, \\\n-                      'added identically in both branches, but permissions', \\\n-                      'conflict', '0%o' % aMode, '->', '0%o' % bMode\n-                print 'CONFLICT: adding with permission:', '0%o' % aMode\n+                output('CONFLICT: File', path,\n+                       'added identically in both branches, but permissions',\n+                       'conflict', '0%o' % aMode, '->', '0%o' % bMode)\n+                output('CONFLICT: adding with permission:', '0%o' % aMode)\n \n                 updateFile(False, aSha, aMode, path)\n             else:\n@@ -785,9 +793,9 @@ def processEntry(entry, branch1Name, bra\n             cleanMerge = False\n             newPath1 = uniquePath(path, branch1Name)\n             newPath2 = uniquePath(path, branch2Name)\n-            print 'CONFLICT (add/add): File', path, \\\n-                  'added non-identically in both branches. Adding as', \\\n-                  newPath1, 'and', newPath2, 'instead.'\n+            output('CONFLICT (add/add): File', path,\n+                   'added non-identically in both branches. Adding as',\n+                   newPath1, 'and', newPath2, 'instead.')\n             removeFile(False, path)\n             updateFile(False, aSha, aMode, newPath1)\n             updateFile(False, bSha, bMode, newPath2)\n@@ -796,7 +804,7 @@ def processEntry(entry, branch1Name, bra\n     #\n     # case D: Modified in both, but differently.\n     #\n-        print 'Auto-merging', path\n+        output('Auto-merging', path)\n         [sha, mode, clean, dummy] = \\\n               mergeFile(path, oSha, oMode,\n                         path, aSha, aMode,\n@@ -806,7 +814,7 @@ def processEntry(entry, branch1Name, bra\n             updateFile(True, sha, mode, path)\n         else:\n             cleanMerge = False\n-            print 'CONFLICT (content): Merge conflict in', path\n+            output('CONFLICT (content): Merge conflict in', path)\n \n             if cacheOnly:\n                 updateFile(False, sha, mode, path)\n---\n0.99.9.GIT\n"}]}