chiark / gitweb /
Use our nice message printout wrapping system
[stgit] / stgit / gitmergeonefile.py
index 5e51b8a9b344a3b36d4f1c47f214d5e2ba35985d..058b6ac4dec8d09939c5887df88381859396baa4 100644 (file)
@@ -19,12 +19,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
 """
 
 import sys, os
+from stgit.exception import *
 from stgit import basedir
 from stgit.config import config, file_extensions, ConfigOption
 from stgit import basedir
 from stgit.config import config, file_extensions, ConfigOption
-from stgit.utils import append_string, out
+from stgit.utils import append_string
+from stgit.out import *
+from stgit.run import *
 
 
-
-class GitMergeException(Exception):
+class GitMergeException(StgException):
     pass
 
 
     pass
 
 
@@ -43,12 +45,8 @@ def __str2none(x):
     else:
         return x
 
     else:
         return x
 
-def __output(cmd):
-    f = os.popen(cmd, 'r')
-    string = f.readline().rstrip()
-    if f.close():
-        raise GitMergeException, 'Error: failed to execute "%s"' % cmd
-    return string
+class MRun(Run):
+    exc = GitMergeException # use a custom exception class on errors
 
 def __checkout_files(orig_hash, file1_hash, file2_hash,
                      path,
 
 def __checkout_files(orig_hash, file1_hash, file2_hash,
                      path,
@@ -61,24 +59,24 @@ def __checkout_files(orig_hash, file1_hash, file2_hash,
 
     if orig_hash:
         orig = path + extensions['ancestor']
 
     if orig_hash:
         orig = path + extensions['ancestor']
-        tmp = __output('git-unpack-file %s' % orig_hash)
+        tmp = MRun('git-unpack-file', orig_hash).output_one_line()
         os.chmod(tmp, int(orig_mode, 8))
         os.renames(tmp, orig)
     if file1_hash:
         src1 = path + extensions['current']
         os.chmod(tmp, int(orig_mode, 8))
         os.renames(tmp, orig)
     if file1_hash:
         src1 = path + extensions['current']
-        tmp = __output('git-unpack-file %s' % file1_hash)
+        tmp = MRun('git-unpack-file', file1_hash).output_one_line()
         os.chmod(tmp, int(file1_mode, 8))
         os.renames(tmp, src1)
     if file2_hash:
         src2 = path + extensions['patched']
         os.chmod(tmp, int(file1_mode, 8))
         os.renames(tmp, src1)
     if file2_hash:
         src2 = path + extensions['patched']
-        tmp = __output('git-unpack-file %s' % file2_hash)
+        tmp = MRun('git-unpack-file', file2_hash).output_one_line()
         os.chmod(tmp, int(file2_mode, 8))
         os.renames(tmp, src2)
 
     if file1_hash and not os.path.exists(path):
         # the current file might be removed by GIT when it is a new
         # file added in both branches. Just re-generate it
         os.chmod(tmp, int(file2_mode, 8))
         os.renames(tmp, src2)
 
     if file1_hash and not os.path.exists(path):
         # the current file might be removed by GIT when it is a new
         # file added in both branches. Just re-generate it
-        tmp = __output('git-unpack-file %s' % file1_hash)
+        tmp = MRun('git-unpack-file', file1_hash).output_one_line()
         os.chmod(tmp, int(file1_mode, 8))
         os.renames(tmp, path)
 
         os.chmod(tmp, int(file1_mode, 8))
         os.renames(tmp, path)