Refactoring: pass more than one file to resolved()
authorKarl Hasselström <kha@treskal.com>
Wed, 19 Dec 2007 18:00:13 +0000 (18:00 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 19 Dec 2007 23:13:30 +0000 (23:13 +0000)
This lets us cut down on the number of calls to git.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/common.py
stgit/commands/resolved.py
stgit/commands/status.py
stgit/run.py

index d040ee9..a0ec90e 100644 (file)
@@ -145,18 +145,18 @@ def print_crt_patch(crt_series, branch = None):
     else:
         out.info('No patches applied')
 
-def resolved(filename, reset = None):
+def resolved(filenames, reset = None):
     if reset:
         stage = {'ancestor': 1, 'current': 2, 'patched': 3}[reset]
-        Run('git', 'checkout-index', '--no-create', '--stage=%d' % stage, '--',
-            filename).no_output()
-    git.add([filename])
-    os.utime(filename, None) # update the access and modificatied times
+        Run('git', 'checkout-index', '--no-create', '--stage=%d' % stage,
+            '--stdin', '-z').input_nulterm(filenames).no_output()
+    git.add(filenames)
+    for filename in filenames:
+        os.utime(filename, None) # update the access and modificatied times
 
 def resolved_all(reset = None):
     conflicts = git.get_conflicts()
-    for filename in conflicts:
-        resolved(filename, reset)
+    resolved(conflicts, reset)
 
 def push_patches(crt_series, patches, check_merged = False):
     """Push multiple patches onto the stack. This function is shared
index 845eca0..792dee5 100644 (file)
@@ -77,7 +77,7 @@ def func(parser, options, args):
                 raise CmdException, 'No conflicts for "%s"' % filename
 
     # resolved
-    for filename in files:
-        if options.interactive:
+    if options.interactive:
+        for filename in files:
             interactive_merge(filename)
-        resolved(filename, options.reset)
+    resolved(files, options.reset)
index 20614b0..370e033 100644 (file)
@@ -109,8 +109,7 @@ def func(parser, options, args):
 
     if options.reset:
         if args:
-            for f in args:
-                resolved(f)
+            resolved(args)
             git.reset(args)
         else:
             resolved_all()
index fa304d0..78537db 100644 (file)
@@ -110,6 +110,9 @@ class Run:
     def input_lines(self, lines):
         self.__indata = ''.join(['%s\n' % line for line in lines])
         return self
+    def input_nulterm(self, lines):
+        self.__indata = ''.join('%s\0' % line for line in lines)
+        return self
     def no_output(self):
         outdata = self.__run_io()
         if outdata: