Skip to content

Commit 46e6517

Browse files
Fredrik KuivinenJunio C Hamano
authored andcommitted
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>
1 parent 5f3aa19 commit 46e6517

File tree

1 file changed

+69
-61
lines changed

1 file changed

+69
-61
lines changed

git-merge-recursive.py

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
sys.path.append('''@@GIT_PYTHON_PATH@@''')
88
from gitMergeCommon import *
99

10+
outputIndent = 0
11+
def output(*args):
12+
sys.stdout.write(' '*outputIndent)
13+
printList(args)
14+
1015
originalIndexFile = os.environ.get('GIT_INDEX_FILE',
1116
os.environ.get('GIT_DIR', '.git') + '/index')
1217
temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \
@@ -41,27 +46,27 @@ def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
4146
assert(isinstance(h1, Commit) and isinstance(h2, Commit))
4247
assert(isinstance(graph, Graph))
4348

44-
def infoMsg(*args):
45-
sys.stdout.write(' '*callDepth)
46-
printList(args)
49+
global outputIndent
4750

48-
infoMsg('Merging:')
49-
infoMsg(h1)
50-
infoMsg(h2)
51+
output('Merging:')
52+
output(h1)
53+
output(h2)
5154
sys.stdout.flush()
5255

5356
ca = getCommonAncestors(graph, h1, h2)
54-
infoMsg('found', len(ca), 'common ancestor(s):')
57+
output('found', len(ca), 'common ancestor(s):')
5558
for x in ca:
56-
infoMsg(x)
59+
output(x)
5760
sys.stdout.flush()
5861

5962
mergedCA = ca[0]
6063
for h in ca[1:]:
64+
outputIndent = callDepth+1
6165
[mergedCA, dummy] = merge(mergedCA, h,
62-
'Temporary shared merge branch 1',
63-
'Temporary shared merge branch 2',
66+
'Temporary merge branch 1',
67+
'Temporary merge branch 2',
6468
graph, callDepth+1)
69+
outputIndent = callDepth
6570
assert(isinstance(mergedCA, Commit))
6671

6772
global cacheOnly
@@ -116,7 +121,7 @@ def mergeTrees(head, merge, common, branch1Name, branch2Name):
116121
assert(isSha(head) and isSha(merge) and isSha(common))
117122

118123
if common == merge:
119-
print 'Already uptodate!'
124+
output('Already uptodate!')
120125
return [head, True]
121126

122127
if cacheOnly:
@@ -554,23 +559,24 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
554559
ren2.processed = True
555560

556561
if ren1.dstName != ren2.dstName:
557-
print 'CONFLICT (rename/rename): Rename', \
558-
fmtRename(path, ren1.dstName), 'in branch', branchName1, \
559-
'rename', fmtRename(path, ren2.dstName), 'in', branchName2
562+
output('CONFLICT (rename/rename): Rename',
563+
fmtRename(path, ren1.dstName), 'in branch', branchName1,
564+
'rename', fmtRename(path, ren2.dstName), 'in',
565+
branchName2)
560566
cleanMerge = False
561567

562568
if ren1.dstName in currentDirectorySet:
563569
dstName1 = uniquePath(ren1.dstName, branchName1)
564-
print ren1.dstName, 'is a directory in', branchName2, \
565-
'adding as', dstName1, 'instead.'
570+
output(ren1.dstName, 'is a directory in', branchName2,
571+
'adding as', dstName1, 'instead.')
566572
removeFile(False, ren1.dstName)
567573
else:
568574
dstName1 = ren1.dstName
569575

570576
if ren2.dstName in currentDirectorySet:
571577
dstName2 = uniquePath(ren2.dstName, branchName2)
572-
print ren2.dstName, 'is a directory in', branchName1, \
573-
'adding as', dstName2, 'instead.'
578+
output(ren2.dstName, 'is a directory in', branchName1,
579+
'adding as', dstName2, 'instead.')
574580
removeFile(False, ren2.dstName)
575581
else:
576582
dstName2 = ren1.dstName
@@ -585,13 +591,14 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
585591
branchName1, branchName2)
586592

587593
if merge or not clean:
588-
print 'Renaming', fmtRename(path, ren1.dstName)
594+
output('Renaming', fmtRename(path, ren1.dstName))
589595

590596
if merge:
591-
print 'Auto-merging', ren1.dstName
597+
output('Auto-merging', ren1.dstName)
592598

593599
if not clean:
594-
print 'CONFLICT (content): merge conflict in', ren1.dstName
600+
output('CONFLICT (content): merge conflict in',
601+
ren1.dstName)
595602
cleanMerge = False
596603

597604
if not cacheOnly:
@@ -615,38 +622,38 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
615622

616623
if ren1.dstName in currentDirectorySet:
617624
newPath = uniquePath(ren1.dstName, branchName1)
618-
print 'CONFLICT (rename/directory): Rename', \
619-
fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,\
620-
'directory', ren1.dstName, 'added in', branchName2
621-
print 'Renaming', ren1.srcName, 'to', newPath, 'instead'
625+
output('CONFLICT (rename/directory): Rename',
626+
fmtRename(ren1.srcName, ren1.dstName), 'in', branchName1,
627+
'directory', ren1.dstName, 'added in', branchName2)
628+
output('Renaming', ren1.srcName, 'to', newPath, 'instead')
622629
cleanMerge = False
623630
removeFile(False, ren1.dstName)
624631
updateFile(False, ren1.dstSha, ren1.dstMode, newPath)
625632
elif srcShaOtherBranch == None:
626-
print 'CONFLICT (rename/delete): Rename', \
627-
fmtRename(ren1.srcName, ren1.dstName), 'in', \
628-
branchName1, 'and deleted in', branchName2
633+
output('CONFLICT (rename/delete): Rename',
634+
fmtRename(ren1.srcName, ren1.dstName), 'in',
635+
branchName1, 'and deleted in', branchName2)
629636
cleanMerge = False
630637
updateFile(False, ren1.dstSha, ren1.dstMode, ren1.dstName)
631638
elif dstShaOtherBranch:
632639
newPath = uniquePath(ren1.dstName, branchName2)
633-
print 'CONFLICT (rename/add): Rename', \
634-
fmtRename(ren1.srcName, ren1.dstName), 'in', \
635-
branchName1 + '.', ren1.dstName, 'added in', branchName2
636-
print 'Adding as', newPath, 'instead'
640+
output('CONFLICT (rename/add): Rename',
641+
fmtRename(ren1.srcName, ren1.dstName), 'in',
642+
branchName1 + '.', ren1.dstName, 'added in', branchName2)
643+
output('Adding as', newPath, 'instead')
637644
updateFile(False, dstShaOtherBranch, dstModeOtherBranch, newPath)
638645
cleanMerge = False
639646
tryMerge = True
640647
elif renames2.getDst(ren1.dstName):
641648
dst2 = renames2.getDst(ren1.dstName)
642649
newPath1 = uniquePath(ren1.dstName, branchName1)
643650
newPath2 = uniquePath(dst2.dstName, branchName2)
644-
print 'CONFLICT (rename/rename): Rename', \
645-
fmtRename(ren1.srcName, ren1.dstName), 'in', \
646-
branchName1+'. Rename', \
647-
fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2
648-
print 'Renaming', ren1.srcName, 'to', newPath1, 'and', \
649-
dst2.srcName, 'to', newPath2, 'instead'
651+
output('CONFLICT (rename/rename): Rename',
652+
fmtRename(ren1.srcName, ren1.dstName), 'in',
653+
branchName1+'. Rename',
654+
fmtRename(dst2.srcName, dst2.dstName), 'in', branchName2)
655+
output('Renaming', ren1.srcName, 'to', newPath1, 'and',
656+
dst2.srcName, 'to', newPath2, 'instead')
650657
removeFile(False, ren1.dstName)
651658
updateFile(False, ren1.dstSha, ren1.dstMode, newPath1)
652659
updateFile(False, dst2.dstSha, dst2.dstMode, newPath2)
@@ -663,13 +670,14 @@ def processRenames(renamesA, renamesB, branchNameA, branchNameB):
663670
branchName1, branchName2)
664671

665672
if merge or not clean:
666-
print 'Renaming', fmtRename(ren1.srcName, ren1.dstName)
673+
output('Renaming', fmtRename(ren1.srcName, ren1.dstName))
667674

668675
if merge:
669-
print 'Auto-merging', ren1.dstName
676+
output('Auto-merging', ren1.dstName)
670677

671678
if not clean:
672-
print 'CONFLICT (rename/modify): Merge conflict in', ren1.dstName
679+
output('CONFLICT (rename/modify): Merge conflict in',
680+
ren1.dstName)
673681
cleanMerge = False
674682

675683
if not cacheOnly:
@@ -714,21 +722,21 @@ def processEntry(entry, branch1Name, branch2Name):
714722
(not aSha and bSha == oSha):
715723
# Deleted in both or deleted in one and unchanged in the other
716724
if aSha:
717-
print 'Removing', path
725+
output('Removing', path)
718726
removeFile(True, path)
719727
else:
720728
# Deleted in one and changed in the other
721729
cleanMerge = False
722730
if not aSha:
723-
print 'CONFLICT (delete/modify):', path, 'deleted in', \
724-
branch1Name, 'and modified in', branch2Name + '.', \
725-
'Version', branch2Name, 'of', path, 'left in tree.'
731+
output('CONFLICT (delete/modify):', path, 'deleted in',
732+
branch1Name, 'and modified in', branch2Name + '.',
733+
'Version', branch2Name, 'of', path, 'left in tree.')
726734
mode = bMode
727735
sha = bSha
728736
else:
729-
print 'CONFLICT (modify/delete):', path, 'deleted in', \
730-
branch2Name, 'and modified in', branch1Name + '.', \
731-
'Version', branch1Name, 'of', path, 'left in tree.'
737+
output('CONFLICT (modify/delete):', path, 'deleted in',
738+
branch2Name, 'and modified in', branch1Name + '.',
739+
'Version', branch1Name, 'of', path, 'left in tree.')
732740
mode = aMode
733741
sha = aSha
734742

@@ -755,14 +763,14 @@ def processEntry(entry, branch1Name, branch2Name):
755763
if path in currentDirectorySet:
756764
cleanMerge = False
757765
newPath = uniquePath(path, addBranch)
758-
print 'CONFLICT (' + conf + '):', \
759-
'There is a directory with name', path, 'in', \
760-
otherBranch + '. Adding', path, 'as', newPath
766+
output('CONFLICT (' + conf + '):',
767+
'There is a directory with name', path, 'in',
768+
otherBranch + '. Adding', path, 'as', newPath)
761769

762770
removeFile(False, path)
763771
updateFile(False, sha, mode, newPath)
764772
else:
765-
print 'Adding', path
773+
output('Adding', path)
766774
updateFile(True, sha, mode, path)
767775

768776
elif not oSha and aSha and bSha:
@@ -772,10 +780,10 @@ def processEntry(entry, branch1Name, branch2Name):
772780
if aSha == bSha:
773781
if aMode != bMode:
774782
cleanMerge = False
775-
print 'CONFLICT: File', path, \
776-
'added identically in both branches, but permissions', \
777-
'conflict', '0%o' % aMode, '->', '0%o' % bMode
778-
print 'CONFLICT: adding with permission:', '0%o' % aMode
783+
output('CONFLICT: File', path,
784+
'added identically in both branches, but permissions',
785+
'conflict', '0%o' % aMode, '->', '0%o' % bMode)
786+
output('CONFLICT: adding with permission:', '0%o' % aMode)
779787

780788
updateFile(False, aSha, aMode, path)
781789
else:
@@ -785,9 +793,9 @@ def processEntry(entry, branch1Name, branch2Name):
785793
cleanMerge = False
786794
newPath1 = uniquePath(path, branch1Name)
787795
newPath2 = uniquePath(path, branch2Name)
788-
print 'CONFLICT (add/add): File', path, \
789-
'added non-identically in both branches. Adding as', \
790-
newPath1, 'and', newPath2, 'instead.'
796+
output('CONFLICT (add/add): File', path,
797+
'added non-identically in both branches. Adding as',
798+
newPath1, 'and', newPath2, 'instead.')
791799
removeFile(False, path)
792800
updateFile(False, aSha, aMode, newPath1)
793801
updateFile(False, bSha, bMode, newPath2)
@@ -796,7 +804,7 @@ def processEntry(entry, branch1Name, branch2Name):
796804
#
797805
# case D: Modified in both, but differently.
798806
#
799-
print 'Auto-merging', path
807+
output('Auto-merging', path)
800808
[sha, mode, clean, dummy] = \
801809
mergeFile(path, oSha, oMode,
802810
path, aSha, aMode,
@@ -806,7 +814,7 @@ def processEntry(entry, branch1Name, branch2Name):
806814
updateFile(True, sha, mode, path)
807815
else:
808816
cleanMerge = False
809-
print 'CONFLICT (content): Merge conflict in', path
817+
output('CONFLICT (content): Merge conflict in', path)
810818

811819
if cacheOnly:
812820
updateFile(False, sha, mode, path)

0 commit comments

Comments
 (0)