Add porcelain.repack().
authorJelmer Vernooij <jelmer@jelmer.uk>
Sun, 13 Sep 2015 14:40:02 +0000 (14:40 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Sun, 13 Sep 2015 14:40:02 +0000 (14:40 +0000)
bin/dulwich
dulwich/porcelain.py
dulwich/tests/test_porcelain.py

index 3fc4e2156066a0a3b04d833565909e88b6f932b2..537ed6f3c0893bec370c67a1186b40cd8a0f0f9a 100755 (executable)
@@ -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,
index 8625b2bae281cc506bb5396dd9b3dc2b582165a7..e65ff58c6d4f76cb218e68b1b731e7d64b9a5ac6 100644 (file)
@@ -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()
index 5aece7a74000b401bfe28f2aa1efee1598b53720..8aa0a5e37a42175887e2aff04c82f77f209a64da 100644 (file)
@@ -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)