Jelmer Vernooij 9 лет назад
Родитель
Сommit
0cbe77c9c1
3 измененных файлов с 31 добавлено и 0 удалено
  1. 7 0
      bin/dulwich
  2. 11 0
      dulwich/porcelain.py
  3. 13 0
      dulwich/tests/test_porcelain.py

+ 7 - 0
bin/dulwich

@@ -239,6 +239,12 @@ def cmd_tag(args):
     porcelain.tag('.', args[0])
 
 
+def cmd_repack(args):
+    opts, args = getopt(args, "", [])
+    opts = dict(opts)
+    porcelain.repack('.')
+
+
 def cmd_reset(args):
     opts, args = getopt(args, "", ["hard", "soft", "mixed"])
     opts = dict(opts)
@@ -369,6 +375,7 @@ commands = {
     "log": cmd_log,
     "ls-remote": cmd_ls_remote,
     "receive-pack": cmd_receive_pack,
+    "repack": cmd_repack,
     "reset": cmd_reset,
     "rev-list": cmd_rev_list,
     "rm": cmd_rm,

+ 11 - 0
dulwich/porcelain.py

@@ -812,3 +812,14 @@ def fetch(repo, remote_location, outstream=sys.stdout, errstream=sys.stderr):
 def ls_remote(remote):
     client, host_path = get_transport_and_path(remote)
     return client.get_refs(encode_path(host_path))
+
+
+def repack(repo):
+    """Repack loose files in a repository.
+
+    Currently this only packs loose objects.
+
+    :param repo: Path to the repository
+    """
+    with open_repo_closing(repo) as r:
+        r.object_store.pack_loose_objects()

+ 13 - 0
dulwich/tests/test_porcelain.py

@@ -740,3 +740,16 @@ class FetchTests(PorcelainTestCase):
         # Check the target repo for pushed changes
         with closing(Repo(target_path)) as r:
             self.assertTrue(self.repo[b'HEAD'].id in r)
+
+
+class RepackTests(PorcelainTestCase):
+
+    def test_empty(self):
+        porcelain.repack(self.repo)
+
+    def test_simple(self):
+        handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
+        os.close(handle)
+        filename = os.path.basename(fullpath)
+        porcelain.add(repo=self.repo.path, paths=filename)
+        porcelain.repack(self.repo)