The actual resolving is done by calling the same subroutine as "git add". Instead of using existing *.{ancestor,current,patches} files, the interactive merge has to create them from the index contents, and delete them afterwards. Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx> --- This goes on top of David's conflict series. stgit/commands/common.py | 16 ++----- stgit/commands/resolved.py | 19 ++------ stgit/gitmergeonefile.py | 99 ++++++++++++++++++++++++-------------------- 3 files changed, 62 insertions(+), 72 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index ad94caf..f31c09b 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -137,18 +137,10 @@ def print_crt_patch(branch = None): def resolved(filename, reset = None): if reset: - reset_file = filename + file_extensions()[reset] - if os.path.isfile(reset_file): - if os.path.isfile(filename): - os.remove(filename) - os.rename(reset_file, filename) - - git.update_cache([filename], force = True) - - for ext in file_extensions().values(): - fn = filename + ext - if os.path.isfile(fn): - os.remove(fn) + stage = {'ancestor': 1, 'current': 2, 'patched': 3}[reset] + Run('git-checkout-index', '--no-create', '--stage=%d' % stage, '--', + filename).no_output() + git.add([filename]) def resolved_all(reset = None): conflicts = git.get_conflicts() diff --git a/stgit/commands/resolved.py b/stgit/commands/resolved.py index 1130641..de38737 100644 --- a/stgit/commands/resolved.py +++ b/stgit/commands/resolved.py @@ -73,18 +73,7 @@ def func(parser, options, args): raise CmdException, 'No conflicts for "%s"' % filename # resolved - try: - for filename in files: - if options.interactive: - interactive_merge(filename) - resolved(filename, options.reset) - del conflicts[conflicts.index(filename)] - finally: - # save or remove the conflicts file. Needs a finally clause to - # ensure that already solved conflicts are marked - if conflicts == []: - os.remove(os.path.join(basedir.get(), 'conflicts')) - else: - f = file(os.path.join(basedir.get(), 'conflicts'), 'w+') - f.writelines([line + '\n' for line in conflicts]) - f.close() + for filename in files: + if options.interactive: + interactive_merge(filename) + resolved(filename, options.reset) diff --git a/stgit/gitmergeonefile.py b/stgit/gitmergeonefile.py index 2aa5ef8..e9bdebb 100644 --- a/stgit/gitmergeonefile.py +++ b/stgit/gitmergeonefile.py @@ -96,51 +96,60 @@ def __conflict(path): def interactive_merge(filename): - """Run the interactive merger on the given file. Note that the - index should not have any conflicts. - """ - extensions = file_extensions() - - ancestor = filename + extensions['ancestor'] - current = filename + extensions['current'] - patched = filename + extensions['patched'] - - if os.path.isfile(ancestor): - three_way = True - files_dict = {'branch1': current, - 'ancestor': ancestor, - 'branch2': patched, - 'output': filename} - imerger = config.get('stgit.i3merge') - else: - three_way = False - files_dict = {'branch1': current, - 'branch2': patched, - 'output': filename} - imerger = config.get('stgit.i2merge') - - if not imerger: - raise GitMergeException, 'No interactive merge command configured' - - # check whether we have all the files for the merge - for fn in [filename, current, patched]: - if not os.path.isfile(fn): - raise GitMergeException, \ - 'Cannot run the interactive merge: "%s" missing' % fn - - mtime = os.path.getmtime(filename) - - out.info('Trying the interactive %s merge' - % (three_way and 'three-way' or 'two-way')) - - err = os.system(imerger % files_dict) - if err != 0: - raise GitMergeException, 'The interactive merge failed: %d' % err - if not os.path.isfile(filename): - raise GitMergeException, 'The "%s" file is missing' % filename - if mtime == os.path.getmtime(filename): - raise GitMergeException, 'The "%s" file was not modified' % filename - + """Run the interactive merger on the given file.""" + try: + extensions = file_extensions() + line = MRun('git-checkout-index', '--stage=all', '--', filename + ).output_one_line() + stages, path = line.split('\t') + stages = dict(zip(['ancestor', 'current', 'patched'], + stages.split(' '))) + for stage, fn in stages.iteritems(): + if stages[stage] == '.': + stages[stage] = None + else: + newname = filename + extensions[stage] + if not os.path.exists(newname): + os.rename(stages[stage], newname) + stages[stage] = newname + + # Check whether we have all the files for the merge. + if not (stages['current'] and stages['patched']): + raise GitMergeException('Cannot run the interactive merge') + + if stages['ancestor']: + three_way = True + files_dict = {'branch1': stages['current'], + 'ancestor': stages['ancestor'], + 'branch2': stages['patched'], + 'output': filename} + imerger = config.get('stgit.i3merge') + else: + three_way = False + files_dict = {'branch1': stages['current'], + 'branch2': stages['patched'], + 'output': filename} + imerger = config.get('stgit.i2merge') + + if not imerger: + raise GitMergeException, 'No interactive merge command configured' + + mtime = os.path.getmtime(filename) + + out.start('Trying the interactive %s merge' + % (three_way and 'three-way' or 'two-way')) + err = os.system(imerger % files_dict) + out.done() + if err != 0: + raise GitMergeException, 'The interactive merge failed' + if not os.path.isfile(filename): + raise GitMergeException, 'The "%s" file is missing' % filename + if mtime == os.path.getmtime(filename): + raise GitMergeException, 'The "%s" file was not modified' % filename + finally: + for fn in stages.itervalues(): + if os.path.isfile(fn): + os.remove(fn) # # Main algorithm - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html