Optimise the git.switch() function
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 23 Aug 2005 12:41:41 +0000 (13:41 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 23 Aug 2005 12:41:41 +0000 (13:41 +0100)
By default it checks the tree status and checks out the given tree id.
This can be done with 'git-read-tree -m old new'.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/git.py

index c1c20c7..ae29eb8 100644 (file)
@@ -452,16 +452,11 @@ def checkout(files = [], tree_id = None, force = False):
 def switch(tree_id):
     """Switch the tree to the given id
     """
-    to_delete = filter(lambda x: x[0] in ['N', 'A'],
-                       __tree_status(tree_id = tree_id))
+    if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
+        raise GitException, 'git-read-tree failed (local changes maybe?)'
 
-    checkout(tree_id = tree_id, force = True)
     __set_head(tree_id)
 
-    # checkout doesn't remove files
-    for fs in to_delete:
-        os.remove(fs[1])
-
 def pull(location, head = None, tag = None):
     """Fetch changes from the remote repository. At the moment, just
     use the 'git fetch' scripts