]> arthur.barton.de Git - bup.git/commitdiff
Add repo abstraction and use it in join
authorRob Browning <rlb@defaultvalue.org>
Tue, 13 Jun 2017 06:44:45 +0000 (01:44 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 24 Sep 2017 17:19:01 +0000 (12:19 -0500)
Operations that can be --remote currently rely on code like this:

  if opt.remote:
      cli = client.Client(opt.remote)
      cat = cli.cat
  else:
      cp = git.CatPipe()
      cat = cp.join

Instead, add LocalRepo and RemoteRepo classes with matching methods so
that we can say:

  repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()

and then use repo methods to handle the work.

Rework "bup join" accordingly.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/join-cmd.py
lib/bup/repo.py [new file with mode: 0644]

index 33935d2ad85d997cc8ded8f7faebc22458b88ff9..b445e4dced2acde43d2d7eee79be295941f659fc 100755 (executable)
@@ -7,8 +7,9 @@ exec "$bup_python" "$0" ${1+"$@"}
 
 import sys
 
-from bup import git, options, client
+from bup import git, options
 from bup.helpers import linereader, log
+from bup.repo import LocalRepo, RemoteRepo
 
 
 optspec = """
@@ -26,22 +27,16 @@ if not extra:
     extra = linereader(sys.stdin)
 
 ret = 0
-
-if opt.remote:
-    cli = client.Client(opt.remote)
-    cat = cli.cat
-else:
-    cp = git.CatPipe()
-    cat = cp.join
+repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()
 
 if opt.o:
     outfile = open(opt.o, 'wb')
 else:
     outfile = sys.stdout
 
-for id in extra:
+for ref in extra:
     try:
-        for blob in cat(id):
+        for blob in repo.join(ref):
             outfile.write(blob)
     except KeyError as e:
         outfile.flush()
diff --git a/lib/bup/repo.py b/lib/bup/repo.py
new file mode 100644 (file)
index 0000000..20dbfcb
--- /dev/null
@@ -0,0 +1,19 @@
+
+from bup import client, git
+
+
+class LocalRepo:
+    def __init__(self, repo_dir=None):
+        self.repo_dir = repo_dir or git.repo()
+        self._cp = git.cp(repo_dir)
+
+    def join(self, ref):
+        return self._cp.join(ref)
+
+class RemoteRepo:
+    def __init__(self, address):
+        self.address = address
+        self.client = client.Client(address)
+
+    def join(self, ref):
+        return self.client.cat(ref)