merge-recursive: Indent the output properly

If we have multiple common ancestors and have to recursively merge
them then the output will be much more readable with this commit.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Fredrik Kuivinen 2005-11-12 00:53:07 +01:00 committed by Junio C Hamano
parent 5f3aa197ac
commit 46e651743a

View File

@ -7,6 +7,11 @@ from sets import Set
sys.path.append('''@@GIT_PYTHON_PATH@@''') sys.path.append('''@@GIT_PYTHON_PATH@@''')
from gitMergeCommon import * from gitMergeCommon import *
outputIndent = 0
def output(*args):
sys.stdout.write(' '*outputIndent)
printList(args)
originalIndexFile = os.environ.get('GIT_INDEX_FILE', originalIndexFile = os.environ.get('GIT_INDEX_FILE',
os.environ.get('GIT_DIR', '.git') + '/index') os.environ.get('GIT_DIR', '.git') + '/index')
temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \ temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \
@ -41,27 +46,27 @@ def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
assert(isinstance(h1, Commit) and isinstance(h2, Commit)) assert(isinstance(h1, Commit) and isinstance(h2, Commit))
assert(isinstance(graph, Graph)) assert(isinstance(graph, Graph))
def infoMsg(*args): global outputIndent
sys.stdout.write(' '*callDepth)
printList(args)
infoMsg('Merging:') output('Merging:')
infoMsg(h1) output(h1)
infoMsg(h2) output(h2)
sys.stdout.flush() sys.stdout.flush()
ca = getCommonAncestors(graph, h1, h2) ca = getCommonAncestors(graph, h1, h2)
infoMsg('found', len(ca), 'common ancestor(s):') output('found', len(ca), 'common ancestor(s):')
for x in ca: for x in ca:
infoMsg(x) output(x)
sys.stdout.flush() sys.stdout.flush()
mergedCA = ca[0] mergedCA = ca[0]
for h in ca[1:]: for h in ca[1:]:
outputIndent = callDepth+1
[mergedCA, dummy] = merge(mergedCA, h, [mergedCA, dummy] = merge(mergedCA, h,
'Temporary shared merge branch 1', 'Temporary merge branch 1',
'Temporary shared merge branch 2', 'Temporary merge branch 2',
graph, callDepth+1) graph, callDepth+1)
outputIndent = callDepth
assert(isinstance(mergedCA, Commit)) assert(isinstance(mergedCA, Commit))
global cacheOnly global cacheOnly
@ -116,7 +121,7 @@ def mergeTrees(head, merge, common, branch1Name, branch2Name):
assert(isSha(head) and isSha(merge) and isSha(common)) assert(isSha(head) and isSha(merge) and isSha(common))
if common == merge: if common == merge:
print 'Already uptodate!' output('Already uptodate!')
return [head, True] return [head, True]
if cacheOnly: if cacheOnly:
@ -554,23 +559,24 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
ren2.processed = True ren2.processed = True
if ren1.dstName != ren2.dstName: if ren1.dstName != ren2.dstName:
print 'CONFLICT (rename/rename): Rename', \ output('CONFLICT (rename/rename): Rename',
fmtRename(path, ren1.dstName), 'in branch', branchName1, \ fmtRename(path, ren1.dstName), 'in branch', branchName1,
'rename', fmtRename(path, ren2.dstName), 'in', branchName2 'rename', fmtRename(path, ren2.dstName), 'in',
branchName2)
cleanMerge = False cleanMerge = False
if ren1.dstName in currentDirectorySet: if ren1.dstName in currentDirectorySet:
dstName1 = uniquePath(ren1.dstName, branchName1) dstName1 = uniquePath(ren1.dstName, branchName1)
print ren1.dstName, 'is a directory in', branchName2, \ output(ren1.dstName, 'is a directory in', branchName2,
'adding as', dstName1, 'instead.' 'adding as', dstName1, 'instead.')
removeFile(False, ren1.dstName) removeFile(False, ren1.dstName)
else: else:
dstName1 = ren1.dstName dstName1 = ren1.dstName
if ren2.dstName in currentDirectorySet: if ren2.dstName in currentDirectorySet:
dstName2 = uniquePath(ren2.dstName, branchName2) dstName2 = uniquePath(ren2.dstName, branchName2)
print ren2.dstName, 'is a directory in', branchName1, \ output(ren2.dstName, 'is a directory in', branchName1,
'adding as', dstName2, 'instead.' 'adding as', dstName2, 'instead.')
removeFile(False, ren2.dstName) removeFile(False, ren2.dstName)
else: else:
dstName2 = ren1.dstName dstName2 = ren1.dstName
@ -585,13 +591,14 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
branchName1, branchName2) branchName1, branchName2)
if merge or not clean: if merge or not clean:
print 'Renaming', fmtRename(path, ren1.dstName) output('Renaming', fmtRename(path, ren1.dstName))
if merge: if merge:
print 'Auto-merging', ren1.dstName output('Auto-merging', ren1.dstName)
if not clean: if not clean:
print 'CONFLICT (content): merge conflict in', ren1.dstName output('CONFLICT (content): merge conflict in',
ren1.dstName)
cleanMerge = False cleanMerge = False
if not cacheOnly: if not cacheOnly:
@ -615,25 +622,25 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
if ren1.dstName in currentDirectorySet: if ren1.dstName in currentDirectorySet:
newPath = uniquePath(ren1.dstName, branchName1) newPath = uniquePath(ren1.dstName, branchName1)
print 'CONFLICT (rename/directory): Rename', \ output('CONFLICT (rename/directory): Rename',
fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,\ fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,
'directory', ren1.dstName, 'added in', branchName2 'directory', ren1.dstName, 'added in', branchName2)
print 'Renaming', ren1.srcName, 'to', newPath, 'instead' output('Renaming', ren1.srcName, 'to', newPath, 'instead')
cleanMerge = False cleanMerge = False
removeFile(False, ren1.dstName) removeFile(False, ren1.dstName)
updateFile(False, ren1.dstSha, ren1.dstMode, newPath) updateFile(False, ren1.dstSha, ren1.dstMode, newPath)
elif srcShaOtherBranch == None: elif srcShaOtherBranch == None:
print 'CONFLICT (rename/delete): Rename', \ output('CONFLICT (rename/delete): Rename',
fmtRename(ren1.srcName, ren1.dstName), 'in', \ fmtRename(ren1.srcName, ren1.dstName), 'in',
branchName1, 'and deleted in', branchName2 branchName1, 'and deleted in', branchName2)
cleanMerge = False cleanMerge = False
updateFile(False, ren1.dstSha, ren1.dstMode, ren1.dstName) updateFile(False, ren1.dstSha, ren1.dstMode, ren1.dstName)
elif dstShaOtherBranch: elif dstShaOtherBranch:
newPath = uniquePath(ren1.dstName, branchName2) newPath = uniquePath(ren1.dstName, branchName2)
print 'CONFLICT (rename/add): Rename', \ output('CONFLICT (rename/add): Rename',
fmtRename(ren1.srcName, ren1.dstName), 'in', \ fmtRename(ren1.srcName, ren1.dstName), 'in',
branchName1 + '.', ren1.dstName, 'added in', branchName2 branchName1 + '.', ren1.dstName, 'added in', branchName2)
print 'Adding as', newPath, 'instead' output('Adding as', newPath, 'instead')
updateFile(False, dstShaOtherBranch, dstModeOtherBranch, newPath) updateFile(False, dstShaOtherBranch, dstModeOtherBranch, newPath)
cleanMerge = False cleanMerge = False
tryMerge = True tryMerge = True
@ -641,12 +648,12 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
dst2 = renames2.getDst(ren1.dstName) dst2 = renames2.getDst(ren1.dstName)
newPath1 = uniquePath(ren1.dstName, branchName1) newPath1 = uniquePath(ren1.dstName, branchName1)
newPath2 = uniquePath(dst2.dstName, branchName2) newPath2 = uniquePath(dst2.dstName, branchName2)
print 'CONFLICT (rename/rename): Rename', \ output('CONFLICT (rename/rename): Rename',
fmtRename(ren1.srcName, ren1.dstName), 'in', \ fmtRename(ren1.srcName, ren1.dstName), 'in',
branchName1+'. Rename', \ branchName1+'. Rename',
fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2 fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2)
print 'Renaming', ren1.srcName, 'to', newPath1, 'and', \ output('Renaming', ren1.srcName, 'to', newPath1, 'and',
dst2.srcName, 'to', newPath2, 'instead' dst2.srcName, 'to', newPath2, 'instead')
removeFile(False, ren1.dstName) removeFile(False, ren1.dstName)
updateFile(False, ren1.dstSha, ren1.dstMode, newPath1) updateFile(False, ren1.dstSha, ren1.dstMode, newPath1)
updateFile(False, dst2.dstSha, dst2.dstMode, newPath2) updateFile(False, dst2.dstSha, dst2.dstMode, newPath2)
@ -663,13 +670,14 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
branchName1, branchName2) branchName1, branchName2)
if merge or not clean: if merge or not clean:
print 'Renaming', fmtRename(ren1.srcName, ren1.dstName) output('Renaming', fmtRename(ren1.srcName, ren1.dstName))
if merge: if merge:
print 'Auto-merging', ren1.dstName output('Auto-merging', ren1.dstName)
if not clean: if not clean:
print 'CONFLICT (rename/modify): Merge conflict in', ren1.dstName output('CONFLICT (rename/modify): Merge conflict in',
ren1.dstName)
cleanMerge = False cleanMerge = False
if not cacheOnly: if not cacheOnly:
@ -714,21 +722,21 @@ def processEntry(entry, branch1Name, branch2Name):
(not aSha and bSha == oSha): (not aSha and bSha == oSha):
# Deleted in both or deleted in one and unchanged in the other # Deleted in both or deleted in one and unchanged in the other
if aSha: if aSha:
print 'Removing', path output('Removing', path)
removeFile(True, path) removeFile(True, path)
else: else:
# Deleted in one and changed in the other # Deleted in one and changed in the other
cleanMerge = False cleanMerge = False
if not aSha: if not aSha:
print 'CONFLICT (delete/modify):', path, 'deleted in', \ output('CONFLICT (delete/modify):', path, 'deleted in',
branch1Name, 'and modified in', branch2Name + '.', \ branch1Name, 'and modified in', branch2Name + '.',
'Version', branch2Name, 'of', path, 'left in tree.' 'Version', branch2Name, 'of', path, 'left in tree.')
mode = bMode mode = bMode
sha = bSha sha = bSha
else: else:
print 'CONFLICT (modify/delete):', path, 'deleted in', \ output('CONFLICT (modify/delete):', path, 'deleted in',
branch2Name, 'and modified in', branch1Name + '.', \ branch2Name, 'and modified in', branch1Name + '.',
'Version', branch1Name, 'of', path, 'left in tree.' 'Version', branch1Name, 'of', path, 'left in tree.')
mode = aMode mode = aMode
sha = aSha sha = aSha
@ -755,14 +763,14 @@ def processEntry(entry, branch1Name, branch2Name):
if path in currentDirectorySet: if path in currentDirectorySet:
cleanMerge = False cleanMerge = False
newPath = uniquePath(path, addBranch) newPath = uniquePath(path, addBranch)
print 'CONFLICT (' + conf + '):', \ output('CONFLICT (' + conf + '):',
'There is a directory with name', path, 'in', \ 'There is a directory with name', path, 'in',
otherBranch + '. Adding', path, 'as', newPath otherBranch + '. Adding', path, 'as', newPath)
removeFile(False, path) removeFile(False, path)
updateFile(False, sha, mode, newPath) updateFile(False, sha, mode, newPath)
else: else:
print 'Adding', path output('Adding', path)
updateFile(True, sha, mode, path) updateFile(True, sha, mode, path)
elif not oSha and aSha and bSha: elif not oSha and aSha and bSha:
@ -772,10 +780,10 @@ def processEntry(entry, branch1Name, branch2Name):
if aSha == bSha: if aSha == bSha:
if aMode != bMode: if aMode != bMode:
cleanMerge = False cleanMerge = False
print 'CONFLICT: File', path, \ output('CONFLICT: File', path,
'added identically in both branches, but permissions', \ 'added identically in both branches, but permissions',
'conflict', '0%o' % aMode, '->', '0%o' % bMode 'conflict', '0%o' % aMode, '->', '0%o' % bMode)
print 'CONFLICT: adding with permission:', '0%o' % aMode output('CONFLICT: adding with permission:', '0%o' % aMode)
updateFile(False, aSha, aMode, path) updateFile(False, aSha, aMode, path)
else: else:
@ -785,9 +793,9 @@ def processEntry(entry, branch1Name, branch2Name):
cleanMerge = False cleanMerge = False
newPath1 = uniquePath(path, branch1Name) newPath1 = uniquePath(path, branch1Name)
newPath2 = uniquePath(path, branch2Name) newPath2 = uniquePath(path, branch2Name)
print 'CONFLICT (add/add): File', path, \ output('CONFLICT (add/add): File', path,
'added non-identically in both branches. Adding as', \ 'added non-identically in both branches. Adding as',
newPath1, 'and', newPath2, 'instead.' newPath1, 'and', newPath2, 'instead.')
removeFile(False, path) removeFile(False, path)
updateFile(False, aSha, aMode, newPath1) updateFile(False, aSha, aMode, newPath1)
updateFile(False, bSha, bMode, newPath2) updateFile(False, bSha, bMode, newPath2)
@ -796,7 +804,7 @@ def processEntry(entry, branch1Name, branch2Name):
# #
# case D: Modified in both, but differently. # case D: Modified in both, but differently.
# #
print 'Auto-merging', path output('Auto-merging', path)
[sha, mode, clean, dummy] = \ [sha, mode, clean, dummy] = \
mergeFile(path, oSha, oMode, mergeFile(path, oSha, oMode,
path, aSha, aMode, path, aSha, aMode,
@ -806,7 +814,7 @@ def processEntry(entry, branch1Name, branch2Name):
updateFile(True, sha, mode, path) updateFile(True, sha, mode, path)
else: else:
cleanMerge = False cleanMerge = False
print 'CONFLICT (content): Merge conflict in', path output('CONFLICT (content): Merge conflict in', path)
if cacheOnly: if cacheOnly:
updateFile(False, sha, mode, path) updateFile(False, sha, mode, path)