[meld] Add CONFLICT types and get_path_for_conflict methods to bzr and git
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Add CONFLICT types and get_path_for_conflict methods to bzr and git
- Date: Thu, 14 Mar 2013 20:55:35 +0000 (UTC)
commit d9153abcc59572c466d669bf5c5bbdccad550d3f
Author: Louis des Landes <louis obsidian com au>
Date: Tue Mar 5 15:46:16 2013 +1100
Add CONFLICT types and get_path_for_conflict methods to bzr and git
meld/tree.py | 4 +++-
meld/vc/_vc.py | 10 ++++++++++
meld/vc/bzr.py | 13 +++++++++++++
meld/vc/git.py | 20 ++++++++++++++++++++
4 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/meld/tree.py b/meld/tree.py
index 349e0d9..dc8c0b9 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -31,7 +31,9 @@ from meld.vc._vc import \
STATE_IGNORED, STATE_NONE, STATE_NORMAL, STATE_NOCHANGE, \
STATE_ERROR, STATE_EMPTY, STATE_NEW, \
STATE_MODIFIED, STATE_CONFLICT, STATE_REMOVED, \
- STATE_MISSING, STATE_NONEXIST, STATE_MAX
+ STATE_MISSING, STATE_NONEXIST, STATE_MAX, \
+ CONFLICT_BASE, CONFLICT_LOCAL, CONFLICT_REMOTE, \
+ CONFLICT_MERGED, CONFLICT_OTHER, CONFLICT_THIS
class DiffTreeStore(gtk.TreeStore):
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index eddb8f3..f517628 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -35,6 +35,16 @@ STATE_ERROR, STATE_EMPTY, STATE_NEW, \
STATE_MODIFIED, STATE_CONFLICT, STATE_REMOVED, \
STATE_MISSING, STATE_NONEXIST, STATE_MAX = list(range(13))
+# VC conflict types
+CONFLICT_MERGED, CONFLICT_BASE, CONFLICT_LOCAL, \
+CONFLICT_REMOTE, CONFLICT_MAX = list(range(5))
+# These names are used by BZR, and are logically identical.
+CONFLICT_OTHER = CONFLICT_REMOTE
+CONFLICT_THIS = CONFLICT_LOCAL
+
+conflicts = ["Merged", "Base", "Local", "Remote"]
+assert len(conflicts) == CONFLICT_MAX
+
class Entry(object):
# These are the possible states of files. Be sure to get the colons correct.
states = _("Ignored:Unversioned:::Error::Newly added:Modified:Conflict:Removed:Missing:Not
present").split(":")
diff --git a/meld/vc/bzr.py b/meld/vc/bzr.py
index e64153c..0e3defa 100644
--- a/meld/vc/bzr.py
+++ b/meld/vc/bzr.py
@@ -38,6 +38,13 @@ class Vc(_vc.CachedVc):
PATCH_INDEX_RE = "^=== modified file '(.*)'.*$"
CONFLICT_RE = "conflict in (.*)$"
+ conflict_map = {
+ _vc.CONFLICT_BASE: '.BASE',
+ _vc.CONFLICT_OTHER: '.OTHER',
+ _vc.CONFLICT_THIS: '.THIS',
+ _vc.CONFLICT_MERGED: '',
+ }
+
# We use None here to indicate flags that we don't deal with or care about
state_1_map = {
" ": None, # First status column empty
@@ -144,3 +151,9 @@ class Vc(_vc.CachedVc):
state = _vc.STATE_NORMAL
retdirs.append( _vc.Dir(path, d, state) )
return retdirs, retfiles
+
+ def get_path_for_conflict(self, path, conflict):
+ if not path.startswith(self.root + os.path.sep):
+ raise _vc.InvalidVCPath(self, path, "Path not in repository")
+
+ return "%s%s" % (path, self.conflict_map[conflict])
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 4933086..7e075cc 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -80,6 +80,26 @@ class Vc(_vc.CachedVc):
def revert_command(self):
return [self.CMD,"checkout"]
+ def get_path_for_conflict(self, path, conflict):
+ if not path.startswith(self.root + os.path.sep):
+ raise _vc.InvalidVCPath(self, path, "Path not in repository")
+ path = path[len(self.root) + 1:]
+
+ args = ["git", "show", ":%s:%s" % (conflict, path)]
+ process = subprocess.Popen(args,
+ cwd=self.location, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ vc_file = process.stdout
+
+ # Error handling here involves doing nothing; in most cases, the only
+ # sane response is to return an empty temp file.
+
+ with tempfile.NamedTemporaryFile(
+ prefix='meld-tmp-%s-' % _vc.conflicts[conflict],
+ delete=False) as f:
+ shutil.copyfileobj(vc_file, f)
+ return f.name
+
def get_path_for_repo_file(self, path, commit=None):
if commit is None:
commit = "HEAD"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]