Преглед на файлове

Add really basic dulwich.porcelain.fsck.

Jelmer Vernooij преди 7 години
родител
ревизия
a463b77dd4
променени са 4 файла, в които са добавени 52 реда и са изтрити 0 реда
  1. 5 0
      NEWS
  2. 10 0
      bin/dulwich
  3. 18 0
      dulwich/porcelain.py
  4. 19 0
      dulwich/tests/test_porcelain.py

+ 5 - 0
NEWS

@@ -1,5 +1,10 @@
 0.19.3	UNRELEASED
 
+ IMPROVEMENTS
+
+  * Add really basic `dulwich.porcelain.fsck` implementation.
+    (Jelmer Vernooij)
+
 0.19.2	2018-04-07
 
  BUG FIXES

+ 10 - 0
bin/dulwich

@@ -112,6 +112,15 @@ class cmd_fetch(Command):
             print("%s -> %s" % item)
 
 
+class cmd_fsck(Command):
+
+    def run(self, args):
+        opts, args = getopt(args, "", [])
+        opts = dict(opts)
+        for (obj, msg) in porcelain.fsck('.'):
+            print("%s: %s" % (obj, msg))
+
+
 class cmd_log(Command):
 
     def run(self, args):
@@ -584,6 +593,7 @@ commands = {
     "dump-index": cmd_dump_index,
     "fetch-pack": cmd_fetch_pack,
     "fetch": cmd_fetch,
+    "fsck": cmd_fsck,
     "help": cmd_help,
     "init": cmd_init,
     "log": cmd_log,

+ 18 - 0
dulwich/porcelain.py

@@ -1239,3 +1239,21 @@ def check_mailmap(repo, contact):
                 raise
             mailmap = Mailmap()
         return mailmap.lookup(contact)
+
+
+def fsck(repo):
+    """Check a repository.
+
+    :param repo: A path to the repository
+    :return: Iterator over errors/warnings
+    """
+    with open_repo_closing(repo) as r:
+        # TODO(jelmer): check pack files
+        # TODO(jelmer): check graph
+        # TODO(jelmer): check refs
+        for sha in r.object_store:
+            o = r.object_store[sha]
+            try:
+                o.check()
+            except Exception as e:
+                yield (sha, e)

+ 19 - 0
dulwich/tests/test_porcelain.py

@@ -1292,3 +1292,22 @@ Jelmer Vernooij <jelmer@debian.org>
             b'Jelmer Vernooij <jelmer@debian.org>',
             porcelain.check_mailmap(
                 self.repo, b'Jelmer Vernooij <jelmer@samba.org>'))
+
+
+class FsckTests(PorcelainTestCase):
+
+    def test_none(self):
+        self.assertEqual(
+                [],
+                list(porcelain.fsck(self.repo)))
+
+    def test_git_dir(self):
+        obj = Tree()
+        a = Blob()
+        a.data = "foo"
+        obj.add(b".git", 0o100644, a.id)
+        self.repo.object_store.add_objects(
+            [(a, None), (obj, None)])
+        self.assertEqual(
+                [(obj.id, 'invalid name .git')],
+                [(sha, str(e)) for (sha, e) in porcelain.fsck(self.repo)])