From: "Karl Hasselström" <kha@treskal.com>
To: "Catalin Marinas" <catalin.marinas@gmail.com>,
"David Kågedal" <davidk@lysator.liu.se>
Cc: git@vger.kernel.org
Subject: [StGit PATCH] Fix "stg resolved" to work with new conflict representation
Date: Mon, 03 Sep 2007 02:04:05 +0200 [thread overview]
Message-ID: <20070903000044.24008.89472.stgit@yoghurt> (raw)
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@treskal.com>
---
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
reply other threads:[~2007-09-03 0:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070903000044.24008.89472.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=davidk@lysator.liu.se \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).