@matheusbsbs / matheus-bagliano / commits / d9a23fa6f7
Fork 0

[PATCH] Be more like the 'resolve' strategy.

If there are non-mergeable changes leave the head contents in the cache and update the working directory with the output from merge(1). In the add/add and delete/modify conflict cases leave unmerged cache entries in the index. Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>

Fredrik Kuivinen committed Sep 13, 2005 at 23:39 UTC d9a23fa6f7124befe7803f5f3a8c53999578caa4
1 file changed +33 -35
git-merge-recursive.py
+33 -35
@@ -7,8 +7,6 @@ from sets import Set
7 sys.path.append('@@GIT_PYTHON_PATH@@')
8 from gitMergeCommon import *
9
10 -alwaysWriteTree = False
11 -
10 # The actual merge code
11 # ---------------------
12
@@ -46,19 +44,14 @@ def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
44 runProgram(['git-update-cache', '-q', '--refresh'])
45 # Use the original index if we only have one common ancestor
46
49 - updateWd = True
50 - if alwaysWriteTree:
51 - cleanCache = True
52 - else:
53 - cleanCache = False
47 + cleanCache = False
48 else:
49 runProgram(['git-read-tree', h1.tree()])
56 - updateWd = False
50 cleanCache = True
51
52 [shaRes, clean] = mergeTrees(h1.tree(), h2.tree(), Ms.tree(),
53 branch1Name, branch2Name,
61 - cleanCache, updateWd)
54 + cleanCache)
55
56 if clean or cleanCache:
57 res = Commit(None, [h1, h2], tree=shaRes)
@@ -125,7 +118,7 @@ def unmergedCacheEntries():
118 return res
119
120 def mergeTrees(head, merge, common, branch1Name, branch2Name,
128 - cleanCache, updateWd):
121 + cleanCache):
122 '''Merge the trees 'head' and 'merge' with the common ancestor
123 'common'. The name of the head branch is 'branch1Name' and the name of
124 the merge branch is 'branch2Name'. Return a tuple (tree, cleanMerge)
@@ -138,10 +131,11 @@ def mergeTrees(head, merge, common, branch1Name, branch2Name,
131 print 'Already uptodate!'
132 return [head, True]
133
141 - if updateWd:
142 - updateArg = '-u'
143 - else:
134 + if cleanCache:
135 updateArg = '-i'
136 + else:
137 + updateArg = '-u'
138 +
139 runProgram(['git-read-tree', updateArg, '-m', common, head, merge])
140 cleanMerge = True
141
@@ -157,7 +151,7 @@ def mergeTrees(head, merge, common, branch1Name, branch2Name,
151 entries = unmergedCacheEntries()
152 for name in entries:
153 if not processEntry(entries[name], branch1Name, branch2Name,
160 - files, dirs, cleanCache, updateWd):
154 + files, dirs, cleanCache):
155 cleanMerge = False
156
157 if cleanMerge or cleanCache:
@@ -169,29 +163,25 @@ def mergeTrees(head, merge, common, branch1Name, branch2Name,
163
164 return [tree, cleanMerge]
165
172 -def processEntry(entry, branch1Name, branch2Name, files, dirs,
173 - cleanCache, updateWd):
166 +def processEntry(entry, branch1Name, branch2Name, files, dirs, cleanCache):
167 '''Merge one cache entry. 'files' is a Set with the files in both of
168 the heads that we are going to merge. 'dirs' contains the
169 corresponding data for directories. If 'cleanCache' is True no
170 non-zero stages will be left in the cache for the path
171 corresponding to the entry 'entry'.'''
172
180 -# cleanCache == True => Don't leave any non-stage 0 entries in the cache.
181 -# False => Leave unmerged entries
182 -
183 -# updateWd == True => Update the working directory to correspond to the cache
184 -# False => Leave the working directory unchanged
173 +# cleanCache == True => Don't leave any non-stage 0 entries in the cache and
174 +# don't update the working directory
175 +# False => Leave unmerged entries and update the working directory
176
177 # clean == True => non-conflict case
178 # False => conflict case
179
180 # If cleanCache == False then the cache shouldn't be updated if clean == False
181
191 - def updateFile(clean, sha, mode, path):
192 - if cleanCache or (not cleanCache and clean):
193 - runProgram(['git-update-cache', '--add', '--cacheinfo',
194 - '0%o' % mode, sha, path])
182 + def updateFile(clean, sha, mode, path, onlyWd=False):
183 + updateCache = not onlyWd and (cleanCache or (not cleanCache and clean))
184 + updateWd = onlyWd or (not cleanCache and clean)
185
186 if updateWd:
187 prog = ['git-cat-file', 'blob', sha]
@@ -213,13 +203,18 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
203 os.symlink(linkTarget, path)
204 else:
205 assert(False)
216 - runProgram(['git-update-cache', '--', path])
206 +
207 + if updateWd and updateCache:
208 + runProgram(['git-update-cache', '--add', '--', path])
209 + elif updateCache:
210 + runProgram(['git-update-cache', '--add', '--cacheinfo',
211 + '0%o' % mode, sha, path])
212
213 def removeFile(clean, path):
214 if cleanCache or (not cleanCache and clean):
215 runProgram(['git-update-cache', '--force-remove', '--', path])
216
222 - if updateWd:
217 + if not cleanCache and clean:
218 try:
219 os.unlink(path)
220 except OSError, e:
@@ -235,8 +230,7 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
230 files.add(newPath)
231 return newPath
232
238 - debug('processing', entry.path, 'clean cache:', cleanCache,
239 - 'wd:', updateWd)
233 + debug('processing', entry.path, 'clean cache:', cleanCache)
234
235 cleanMerge = True
236
@@ -327,9 +321,9 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
321 if aMode != bMode:
322 cleanMerge = False
323 print 'CONFLICT: File "' + path + \
330 - '" added identically in both branches,'
331 - print 'CONFLICT: but permissions conflict', '0%o' % aMode, \
332 - '->', '0%o' % bMode
324 + '" added identically in both branches,', \
325 + 'but permissions conflict', '0%o' % aMode, '->', \
326 + '0%o' % bMode
327 print 'CONFLICT: adding with permission:', '0%o' % aMode
328
329 updateFile(False, aSha, aMode, path)
@@ -341,8 +335,7 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
335 newPath1 = uniquePath(path, branch1Name)
336 newPath2 = uniquePath(path, branch2Name)
337 print 'CONFLICT (add/add): File "' + path + \
344 - '" added non-identically in both branches.', \
345 - 'Adding "' + newPath1 + '" and "' + newPath2 + '" instead.'
338 + '" added non-identically in both branches.'
339 removeFile(False, path)
340 updateFile(False, aSha, aMode, newPath1)
341 updateFile(False, bSha, bMode, newPath2)
@@ -372,7 +365,12 @@ def processEntry(entry, branch1Name, branch2Name, files, dirs,
365 if ret != 0:
366 cleanMerge = False
367 print 'CONFLICT (content): Merge conflict in "' + path + '".'
375 - updateFile(False, sha, mode, path)
368 +
369 + if cleanCache:
370 + updateFile(False, sha, mode, path)
371 + else:
372 + updateFile(True, aSha, aMode, path)
373 + updateFile(False, sha, mode, path, True)
374 else:
375 updateFile(True, sha, mode, path)
376