Răsfoiți Sursa

Add --name-status argument to porcelain.log.

Jelmer Vernooij 8 ani în urmă
părinte
comite
a4326ca82d
2 a modificat fișierele cu 50 adăugiri și 4 ștergeri
  1. 7 3
      bin/dulwich
  2. 43 1
      dulwich/porcelain.py

+ 7 - 3
bin/dulwich

@@ -23,8 +23,8 @@
 
 """Simple command-line interface to Dulwich>
 
-This is a very simple command-line wrapper for Dulwich. It is by 
-no means intended to be a full-blown Git command-line interface but just 
+This is a very simple command-line wrapper for Dulwich. It is by
+no means intended to be a full-blown Git command-line interface but just
 a way to test Dulwich.
 """
 
@@ -98,9 +98,13 @@ def cmd_log(args):
     parser = optparse.OptionParser()
     parser.add_option("--reverse", dest="reverse", action="store_true",
                       help="Reverse order in which entries are printed")
+    parser.add_option("--name-status", dest="name_status", action="store_true",
+                      help="Print name/status for each changed file")
     options, args = parser.parse_args(args)
 
-    porcelain.log(".", paths=args, reverse=options.reverse, outstream=sys.stdout)
+    porcelain.log(".", paths=args, reverse=options.reverse,
+                  name_status=options.name_status,
+                  outstream=sys.stdout)
 
 
 def cmd_diff(args):

+ 43 - 1
dulwich/porcelain.py

@@ -68,6 +68,14 @@ from dulwich.archive import (
 from dulwich.client import (
     get_transport_and_path,
     )
+from dulwich.diff_tree import (
+    CHANGE_ADD,
+    CHANGE_DELETE,
+    CHANGE_MODIFY,
+    CHANGE_RENAME,
+    CHANGE_COPY,
+    RENAME_CHANGE_TYPES,
+    )
 from dulwich.errors import (
     SendPackError,
     UpdateRefsError,
@@ -423,14 +431,45 @@ def show_object(repo, obj, decode, outstream):
             }[obj.type_name](repo, obj, decode, outstream)
 
 
+def print_name_status(changes):
+    """Print a simple status summary, listing changed files.
+    """
+    for change in changes:
+        if not change:
+            continue
+        if type(change) is list:
+            change = change[0]
+        if change.type == CHANGE_ADD:
+            path1 = change.new.path
+            path2 = ''
+            kind = 'A'
+        elif change.type == CHANGE_DELETE:
+            path1 = change.old.path
+            path2 = ''
+            kind = 'D'
+        elif change.type == CHANGE_MODIFY:
+            path1 = change.new.path
+            path2 = ''
+            kind = 'M'
+        elif change.type in RENAME_CHANGE_TYPES:
+            path1 = change.old.path
+            path2 = change.new.path
+            if change.type == CHANGE_RENAME:
+                kind = 'R'
+            elif change.type == CHANGE_COPY:
+                kind = 'C'
+        yield '%-8s%-20s%-20s' % (kind, path1, path2)
+
+
 def log(repo=".", paths=None, outstream=sys.stdout, max_entries=None,
-        reverse=False):
+        reverse=False, name_status=False):
     """Write commit logs.
 
     :param repo: Path to repository
     :param paths: Optional set of specific paths to print entries for
     :param outstream: Stream to write log output to
     :param reverse: Reverse order in which entries are printed
+    :param name_status: Print name status
     :param max_entries: Optional maximum number of entries to display
     """
     with open_repo_closing(repo) as r:
@@ -439,6 +478,9 @@ def log(repo=".", paths=None, outstream=sys.stdout, max_entries=None,
         for entry in walker:
             decode = lambda x: commit_decode(entry.commit, x)
             print_commit(entry.commit, decode, outstream)
+            if name_status:
+                outstream.writelines(
+                    [l+'\n' for l in print_name_status(entry.changes())])
 
 
 # TODO(jelmer): better default for encoding?