[meld] vc: Move hack for adding from parents into individual VCs



commit ed46b0f7f92b88e61e97432ee34d8e7a85ce8e25
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Aug 24 07:31:46 2013 +1000

    vc: Move hack for adding from parents into individual VCs
    
    CVS and older SVN require directories to be added from their direct
    parents. This was dealt with via a hack in VcView. This commit moves
    the hack into the CVS and SVN modules, and adds an accompanying
    new-style API call for adding files.

 meld/vc/_vc.py |    3 +++
 meld/vc/cvs.py |   14 +++++++++++---
 meld/vc/git.py |    7 ++++---
 meld/vc/svn.py |   13 +++++++++++--
 meld/vcview.py |   15 +++------------
 5 files changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index be3c8c2..267dd1c 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -154,6 +154,9 @@ class Vc(object):
     def get_commits_to_push_summary(self):
         raise NotImplementedError()
 
+    def add(self, runner, files):
+        raise NotImplementedError()
+
     def remove(self, runner, files):
         raise NotImplementedError()
 
diff --git a/meld/vc/cvs.py b/meld/vc/cvs.py
index 1479de6..8a9dc60 100644
--- a/meld/vc/cvs.py
+++ b/meld/vc/cvs.py
@@ -64,9 +64,6 @@ class Vc(_vc.Vc):
     def update_command(self):
         return [self.CMD, "update"]
 
-    def add_command(self):
-        return [self.CMD, "add"]
-
     def remove_command(self, force=0):
         return [self.CMD, "rm", "-f"]
 
@@ -121,6 +118,17 @@ class Vc(_vc.Vc):
             if os.path.exists(destfile):
                 os.rmdir(tmpdir)
 
+    def add(self, runner, files):
+        # CVS needs to add folders from their immediate parent
+        dirs = [s for s in files if os.path.isdir(s)]
+        files = [s for s in files if os.path.isfile(s)]
+        command = [self.CMD, 'add']
+        for path in dirs:
+            runner(command, [path], refresh=True,
+                   working_dir=os.path.dirname(path))
+        if files:
+            runner(command, files, refresh=True)
+
     def _get_dirsandfiles(self, directory, dirs, files):
         vc_path = os.path.join(directory, self.VC_DIR)
 
diff --git a/meld/vc/git.py b/meld/vc/git.py
index 477ef86..5949951 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -87,9 +87,6 @@ class Vc(_vc.CachedVc):
     def commit_command(self, message):
         return [self.CMD, "commit", "-m", message]
 
-    def add_command(self):
-        return [self.CMD, "add"]
-
     # Prototyping VC interface version 2
 
     def update_actions_for_paths(self, path_states, actions):
@@ -190,6 +187,10 @@ class Vc(_vc.CachedVc):
         command = [self.CMD, 'push']
         runner(command, [], refresh=True, working_dir=self.root)
 
+    def add(self, runner, files):
+        command = [self.CMD, 'add']
+        runner(command, files, refresh=True, working_dir=self.root)
+
     def remove(self, runner, files):
         command = [self.CMD, 'rm', '-r']
         runner(command, files, refresh=True, working_dir=self.root)
diff --git a/meld/vc/svn.py b/meld/vc/svn.py
index 321b8ee..72dbc50 100644
--- a/meld/vc/svn.py
+++ b/meld/vc/svn.py
@@ -57,8 +57,7 @@ class Vc(_vc.CachedVc):
 
     def update_command(self):
         return [self.CMD,"update"]
-    def add_command(self):
-        return [self.CMD,"add"]
+
     def remove_command(self, force=0):
         return [self.CMD,"rm","--force"]
     def revert_command(self):
@@ -143,6 +142,16 @@ class Vc(_vc.CachedVc):
 
         raise KeyError("Conflict file does not exist")
 
+    def add(self, runner, files):
+        # SVN < 1.7 needs to add folders from their immediate parent
+        dirs = [s for s in files if os.path.isdir(s)]
+        files = [s for s in files if os.path.isfile(s)]
+        command = [self.CMD, 'add']
+        for path in dirs:
+            runner(command, [path], refresh=True,
+                   working_dir=os.path.dirname(path))
+        if files:
+            runner(command, files, refresh=True)
 
     @classmethod
     def _repo_version_support(cls, version):
diff --git a/meld/vcview.py b/meld/vcview.py
index b5d4088..2f46007 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -680,18 +680,9 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         vcdialogs.CommitDialog(self).run()
 
     def on_button_add_clicked(self, obj):
-        # This is an evil hack to let CVS and SVN < 1.7 deal with the
-        # requirement of adding folders from their immediate parent.
-        if self.vc.NAME in ("CVS", "Subversion"):
-            selected = self._get_selected_files()
-            dirs = [s for s in selected if os.path.isdir(s)]
-            files = [s for s in selected if os.path.isfile(s)]
-            for path in dirs:
-                self._command(self.vc.add_command(), [path],
-                              working_dir=os.path.dirname(path))
-            if files:
-                self._command(self.vc.add_command(), files)
-        else:
+        try:
+            self.vc.add(self._command, self._get_selected_files())
+        except NotImplementedError:
             self._command_on_selected(self.vc.add_command())
 
     def on_button_remove_clicked(self, obj):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]