From d7fade4be437ade1eaf92ca29cc99b566b0e3c18 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Tue, 9 May 2006 21:21:28 +0100 Subject: [PATCH] Allow configurable file extensions for merge conflicts The files left after a merge conflict had confusing extensions. This patch adds the "extensions" config option and also sets the defaults to ".ancestor", ".current" and ".patched". Signed-off-by: Catalin Marinas --- examples/stgitrc | 8 ++++++-- stgit/commands/common.py | 5 +++-- stgit/commands/resolved.py | 9 ++++++--- stgit/config.py | 23 ++++++++++++++++++++++- stgit/gitmergeonefile.py | 8 ++++---- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/examples/stgitrc b/examples/stgitrc index 568bc16..ed8cc96 100644 --- a/examples/stgitrc +++ b/examples/stgitrc @@ -30,10 +30,10 @@ smtpserver: localhost:25 # Different three-way merge tools below. Uncomment the preferred one. # Note that the 'output' file contains the same data as 'branch1'. This # is useful for tools that do not take an output parameter -merger: diff3 -L local -L older -L remote -m -E \ +merger: diff3 -L current -L ancestor -L patched -m -E \ "%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s" -#merger: xxdiff --title1 local --title2 older --title3 remote \ +#merger: xxdiff --title1 current --title2 ancestor --title3 patched \ # --show-merged-pane -m -E -O -X -M "%(output)s" \ # "%(branch1)s" "%(ancestor)s" "%(branch2)s" @@ -42,3 +42,7 @@ merger: diff3 -L local -L older -L remote -m -E \ # Leave the original files in the working tree in case of a merge conflict keeporig: yes + +# Extensions for the files involved in a three-way merge (ancestor, +# current, patched) +#extensions: .ancestor .current .patched diff --git a/stgit/commands/common.py b/stgit/commands/common.py index b8aa1c0..c6ca514 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -23,6 +23,7 @@ from optparse import OptionParser, make_option from stgit.utils import * from stgit import stack, git, basedir +from stgit.config import config, file_extensions crt_series = None @@ -112,7 +113,7 @@ def print_crt_patch(branch = None): def resolved(filename, reset = None): if reset: - reset_file = filename + '.' + reset + reset_file = filename + file_extensions()[reset] if os.path.isfile(reset_file): if os.path.isfile(filename): os.remove(filename) @@ -120,7 +121,7 @@ def resolved(filename, reset = None): git.update_cache([filename], force = True) - for ext in ['.local', '.older', '.remote']: + for ext in file_extensions().values(): fn = filename + ext if os.path.isfile(fn): os.remove(fn) diff --git a/stgit/commands/resolved.py b/stgit/commands/resolved.py index 2c968d0..186bc73 100644 --- a/stgit/commands/resolved.py +++ b/stgit/commands/resolved.py @@ -22,6 +22,7 @@ from optparse import OptionParser, make_option from stgit.commands.common import * from stgit.utils import * from stgit import stack, git, basedir +from stgit.config import file_extensions help = 'mark a file conflict as solved' @@ -29,19 +30,21 @@ usage = """%prog [options] [] Mark a merge conflict as resolved. The conflicts can be seen with the 'status' command, the corresponding files being prefixed with a -'C'. This command also removes any .{local,remote,older} files.""" +'C'. This command also removes any .{ancestor,current,patched} +files.""" options = [make_option('-a', '--all', help = 'mark all conflicts as solved', action = 'store_true'), - make_option('-r', '--reset', metavar = '(local|remote|older)', + make_option('-r', '--reset', metavar = '(ancestor|current|patched)', help = 'reset the file(s) to the given state')] def func(parser, options, args): """Mark the conflict as resolved """ - if options.reset and options.reset not in ['local', 'remote', 'older']: + if options.reset \ + and options.reset not in file_extensions(): raise CmdException, 'Unknown reset state: %s' % options.reset if options.all: diff --git a/stgit/config.py b/stgit/config.py index 66e9f41..c404c64 100644 --- a/stgit/config.py +++ b/stgit/config.py @@ -31,9 +31,10 @@ config.set('stgit', 'autoresolved', 'no') config.set('stgit', 'smtpserver', 'localhost:25') config.set('stgit', 'smtpdelay', '2') config.set('stgit', 'merger', - 'diff3 -L local -L older -L remote -m -E ' \ + 'diff3 -L current -L ancestor -L patched -m -E ' \ '"%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s"') config.set('stgit', 'keeporig', 'yes') +config.set('stgit', 'extensions', '.ancestor .current .patched') # Read the configuration files (if any) and override the default settings config.read('/etc/stgitrc') @@ -49,3 +50,23 @@ if config.has_option('stgit', 'pager'): if config.has_section('gitmergeonefile'): for option, value in config.items('gitmergeonefile'): config.set('stgit', option, value) + + +# cached extensions +__extensions = None + +def file_extensions(): + """Returns a dictionary with the conflict file extensions + """ + global __extensions + + if not __extensions: + cfg_ext = config.get('stgit', 'extensions').split() + if len(cfg_ext) != 3: + raise CmdException, '"extensions" configuration error' + + __extensions = { 'ancestor': cfg_ext[0], + 'current': cfg_ext[1], + 'patched': cfg_ext[2] } + + return __extensions diff --git a/stgit/gitmergeonefile.py b/stgit/gitmergeonefile.py index c3aaa2a..136552b 100644 --- a/stgit/gitmergeonefile.py +++ b/stgit/gitmergeonefile.py @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os from stgit import basedir -from stgit.config import config +from stgit.config import config, file_extensions from stgit.utils import append_string @@ -62,17 +62,17 @@ def __checkout_files(orig_hash, file1_hash, file2_hash, global orig, src1, src2 if orig_hash: - orig = '%s.older' % path + orig = path + file_extensions()['ancestor'] tmp = __output('git-unpack-file %s' % orig_hash) os.chmod(tmp, int(orig_mode, 8)) os.renames(tmp, orig) if file1_hash: - src1 = '%s.local' % path + src1 = path + file_extensions()['current'] tmp = __output('git-unpack-file %s' % file1_hash) os.chmod(tmp, int(file1_mode, 8)) os.renames(tmp, src1) if file2_hash: - src2 = '%s.remote' % path + src2 = path + file_extensions()['patched'] tmp = __output('git-unpack-file %s' % file2_hash) os.chmod(tmp, int(file2_mode, 8)) os.renames(tmp, src2) -- 2.11.0