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>
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 = """
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()
--- /dev/null
+
+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)