Add the --unrelated option to mail
[stgit] / stgit / git.py
index 7358fae..1f57481 100644 (file)
@@ -158,7 +158,7 @@ def _input(cmd, file_desc):
         p.tochild.write(line)
     p.tochild.close()
     if p.wait():
-        raise GitException, '%s failed (%s)' % (str(cmd),
+        raise GitException, '%s failed (%s)' % (' '.join(cmd),
                                                 p.childerr.read().strip())
 
 def _input_str(cmd, string):
@@ -166,14 +166,14 @@ def _input_str(cmd, string):
     p.tochild.write(string)
     p.tochild.close()
     if p.wait():
-        raise GitException, '%s failed (%s)' % (str(cmd),
+        raise GitException, '%s failed (%s)' % (' '.join(cmd),
                                                 p.childerr.read().strip())
 
 def _output(cmd):
     p=popen2.Popen3(cmd, True)
     output = p.fromchild.read()
     if p.wait():
-        raise GitException, '%s failed (%s)' % (str(cmd),
+        raise GitException, '%s failed (%s)' % (' '.join(cmd),
                                                 p.childerr.read().strip())
     return output
 
@@ -185,7 +185,7 @@ def _output_one_line(cmd, file_desc = None):
         p.tochild.close()
     output = p.fromchild.readline().strip()
     if p.wait():
-        raise GitException, '%s failed (%s)' % (str(cmd),
+        raise GitException, '%s failed (%s)' % (' '.join(cmd),
                                                 p.childerr.read().strip())
     return output
 
@@ -193,7 +193,7 @@ def _output_lines(cmd):
     p=popen2.Popen3(cmd, True)
     lines = p.fromchild.readlines()
     if p.wait():
-        raise GitException, '%s failed (%s)' % (str(cmd),
+        raise GitException, '%s failed (%s)' % (' '.join(cmd),
                                                 p.childerr.read().strip())
     return lines
 
@@ -216,8 +216,8 @@ def __run(cmd, args=None):
         return r
     return 0
 
-def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
-                  noexclude = True, verbose = False):
+def tree_status(files = None, tree_id = 'HEAD', unknown = False,
+                  noexclude = True, verbose = False, diff_flags = []):
     """Returns a list of pairs - [status, filename]
     """
     if verbose:
@@ -254,7 +254,8 @@ def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
     cache_files += [('C', filename) for filename in conflicts]
 
     # the rest
-    for line in _output_lines(['git-diff-index', tree_id, '--'] + files):
+    for line in _output_lines(['git-diff-index'] + diff_flags +
+                              [ tree_id, '--'] + files):
         fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
         if fs[1] not in conflicts:
             cache_files.append(fs)
@@ -267,7 +268,7 @@ def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
 def local_changes(verbose = True):
     """Return true if there are local changes in the tree
     """
-    return len(__tree_status(verbose = verbose)) != 0
+    return len(tree_status(verbose = verbose)) != 0
 
 # HEAD value cached
 __head = None
@@ -566,7 +567,7 @@ def update_cache(files = None, force = False):
     if not files:
         files = []
 
-    cache_files = __tree_status(files, verbose = False)
+    cache_files = tree_status(files, verbose = False)
 
     # everything is up-to-date
     if len(cache_files) == 0:
@@ -737,13 +738,15 @@ def merge(base, head1, head2, recursive = False):
         raise GitException, 'GIT index merging failed (possible conflicts)'
 
 def status(files = None, modified = False, new = False, deleted = False,
-           conflict = False, unknown = False, noexclude = False):
+           conflict = False, unknown = False, noexclude = False,
+           diff_flags = []):
     """Show the tree status
     """
     if not files:
         files = []
 
-    cache_files = __tree_status(files, unknown = True, noexclude = noexclude)
+    cache_files = tree_status(files, unknown = True, noexclude = noexclude,
+                                diff_flags = diff_flags)
     all = not (modified or new or deleted or conflict or unknown)
 
     if not all:
@@ -809,12 +812,12 @@ def diffstat(files = None, rev1 = 'HEAD', rev2 = None):
         raise GitException, 'git.diffstat failed'
     return diff_str
 
-def files(rev1, rev2):
+def files(rev1, rev2, diff_flags = []):
     """Return the files modified between rev1 and rev2
     """
 
     result = ''
-    for line in _output_lines(['git-diff-tree''-r', rev1, rev2]):
+    for line in _output_lines(['git-diff-tree'] + diff_flags + ['-r', rev1, rev2]):
         result += '%s %s\n' % tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
 
     return result.rstrip()
@@ -829,11 +832,11 @@ def barefiles(rev1, rev2):
 
     return result.rstrip()
 
-def pretty_commit(commit_id = 'HEAD'):
+def pretty_commit(commit_id = 'HEAD', diff_flags = []):
     """Return a given commit (log + diff)
     """
-    return _output(['git-diff-tree', '--cc', '--always', '--pretty', '-r',
-                    commit_id])
+    return _output(['git-diff-tree'] + diff_flags +
+                   ['--cc', '--always', '--pretty', '-r', commit_id])
 
 def checkout(files = None, tree_id = None, force = False):
     """Check out the given or all files
@@ -873,7 +876,7 @@ def reset(files = None, tree_id = None, check_out = True):
         tree_id = get_head()
 
     if check_out:
-        cache_files = __tree_status(files, tree_id)
+        cache_files = tree_status(files, tree_id)
         # files which were added but need to be removed
         rm_files =  [x[1] for x in cache_files if x[0] in ['A']]
 
@@ -1067,3 +1070,9 @@ def fetch_head():
 
     # here we are sure to have a single fetch_head
     return fetch_head
+
+def all_refs():
+    """Return a list of all refs in the current repository.
+    """
+
+    return [line.split()[1] for line in _output_lines(['git-show-ref'])]