Commit 10c3e63e authored by Kai Willadsen's avatar Kai Willadsen

vc.git: Support showing (partially) staged status of files (bgo#755112)

The use case here is that it's nice to know what you still need to look
at, particularly in more complicated merges. We only differentiate
between files that are unstaged, fully staged and partially staged.

Actually having a real staging area view is an orthogonal consideration,
and would still be nice.
parent c3778997
...@@ -32,19 +32,23 @@ import shutil ...@@ -32,19 +32,23 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from collections import defaultdict
from meld.conf import _, ngettext from meld.conf import _, ngettext
from . import _vc from . import _vc
NULL_SHA = "0000000000000000000000000000000000000000"
class Vc(_vc.Vc): class Vc(_vc.Vc):
CMD = "git" CMD = "git"
NAME = "Git" NAME = "Git"
VC_DIR = ".git" VC_DIR = ".git"
GIT_DIFF_FILES_RE = ":(\d+) (\d+) [a-z0-9]+ [a-z0-9]+ ([XADMTU])\t(.*)" GIT_DIFF_FILES_RE = ":(\d+) (\d+) ([a-z0-9]+) ([a-z0-9]+) ([XADMTU])\t(.*)"
DIFF_RE = re.compile(GIT_DIFF_FILES_RE) DIFF_RE = re.compile(GIT_DIFF_FILES_RE)
conflict_map = { conflict_map = {
...@@ -127,7 +131,7 @@ class Vc(_vc.Vc): ...@@ -127,7 +131,7 @@ class Vc(_vc.Vc):
for p in paths: for p in paths:
if os.path.isdir(p): if os.path.isdir(p):
entries = self._get_modified_files(p) entries = self._get_modified_files(p)
names = [self.DIFF_RE.search(e).groups()[3] for e in entries] names = [self.DIFF_RE.search(e).groups()[5] for e in entries]
files.extend(names) files.extend(names)
else: else:
files.append(os.path.relpath(p, self.root)) files.append(os.path.relpath(p, self.root))
...@@ -298,15 +302,28 @@ class Vc(_vc.Vc): ...@@ -298,15 +302,28 @@ class Vc(_vc.Vc):
# to STATE_NORMAL. # to STATE_NORMAL.
self._tree_cache[get_real_path(path)] = _vc.STATE_NORMAL self._tree_cache[get_real_path(path)] = _vc.STATE_NORMAL
else: else:
tree_meta_cache = defaultdict(list)
staged = set()
unstaged = set()
for entry in entries: for entry in entries:
columns = self.DIFF_RE.search(entry).groups() columns = self.DIFF_RE.search(entry).groups()
old_mode, new_mode, statekey, path = columns old_mode, new_mode, old_sha, new_sha, statekey, path = columns
state = self.state_map.get(statekey.strip(), _vc.STATE_NONE) state = self.state_map.get(statekey.strip(), _vc.STATE_NONE)
self._tree_cache[get_real_path(path)] = state self._tree_cache[get_real_path(path)] = state
if old_mode != new_mode: if old_mode != new_mode:
msg = _("Mode changed from %s to %s" % msg = _("Mode changed from %s to %s" %
(old_mode, new_mode)) (old_mode, new_mode))
self._tree_meta_cache[path] = msg tree_meta_cache[path].append(msg)
collection = unstaged if new_sha == NULL_SHA else staged
collection.add(path)
for path in staged:
tree_meta_cache[path].append(
_("Partially staged") if path in unstaged else _("Staged"))
for path, msgs in tree_meta_cache.items():
self._tree_meta_cache[get_real_path(path)] = "; ".join(msgs)
for path in ignored_entries: for path in ignored_entries:
self._tree_cache[get_real_path(path)] = _vc.STATE_IGNORED self._tree_cache[get_real_path(path)] = _vc.STATE_IGNORED
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment