Skip to content

Commit 9d9fa98

Browse files
committed
fetch
1 parent ab91b26 commit 9d9fa98

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

git-incrypt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ plugin.mktemplate.argtypes = [ctypes.c_char_p, ctypes.c_char_p,
5757
ctypes.c_char_p, ctypes.c_char_p,
5858
ctypes.c_char_p]
5959
plugin.mktemplate.restype = ctypes.c_char_p
60+
plugin.fetchpattern.argtypes = [ctypes.c_char]
6061

6162
if not hasattr(pygit2.enums, 'FileMode'):
6263
class FileMode(enum.IntFlag):
@@ -182,7 +183,7 @@ class CryptRepo:
182183
self.trust(force=True, sign=True)
183184
else:
184185
self.repo = pygit2.Repository('.')
185-
self._fetch('_')
186+
plugin.fetchpattern('_'.encode('utf-8')[0])
186187
self.meta = MetaData(self.repo).read()
187188
if forcetrust:
188189
self.trust(force=forcetrust)
@@ -230,16 +231,6 @@ class CryptRepo:
230231
([f'^{x}\n' for x in excl] if excl else [])))
231232
return text.strip().split('\n') if text else []
232233

233-
def _fetch(self, pattern):
234-
subprocess.run(
235-
['git', 'fetch',
236-
CryptRepo.verbosityflags[plugin.getverbosity()],
237-
'--progress' if plugin.getprogress() else '--no-progress',
238-
'--no-write-fetch-head', '-p', plugin.geturl().decode('utf-8'),
239-
f'+refs/heads/{pattern}:{
240-
plugin.getprefix().decode("utf-8")}1/{pattern}'],
241-
cwd=self.repo.path, check=True, stdout=sys.stderr)
242-
243234
def trust(self, force=False, sign=False):
244235
'trust this repository'
245236
if force:
@@ -275,7 +266,7 @@ class CryptRepo:
275266
'decrypt an object'
276267
raw = decryptdata(self.repo.get(oid).read_raw(), self.meta.key)
277268
return self.repo.odb.write(raw[20], raw[21:])
278-
self._fetch('*')
269+
plugin.fetchpattern('*'.encode('utf-8')[0])
279270
self.meta.read()
280271
self.trust()
281272
# [ dec(crypt) , prefdec(crypt), crypt ]

incrypt-plugin.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "hex.h"
1414
#include "setup.h"
1515
#include "ident.h"
16+
#include "run-command.h"
1617

1718
void globalinit(const char* dir, const char* url_arg);
1819
int set_option(const char *name, size_t namelen, const char *value);
@@ -34,6 +35,7 @@ char* hashdatahex(const unsigned char* input, size_t inputlen,
3435
char* output);
3536
void initbare(const char* dir);
3637
char* mktemplate(const char* name, const char* email, const char* date, const char* msg, char* output);
38+
void fetchpattern(const char pattern);
3739

3840
/*static*/ const char* CRYPTREADME = "# 401 Unauthorized\n\n"
3941
"This is an encrypted git repository. You can clone it, but you will not be\n"
@@ -347,6 +349,26 @@ char* mktemplate(const char* name, const char* email, const char* date, const ch
347349
return output;
348350
}
349351

352+
static const char* verbosityflags[5] = {"-q", "-q", "-v", "-vv", "-vvv"};
353+
static const char* progressflags[2] = {"--no-progress", "--progress"};
354+
355+
void fetchpattern(const char pattern) {
356+
struct child_process cmd = CHILD_PROCESS_INIT;
357+
358+
char refspec[14+GIT_SHA1_HEXSZ+14+4];
359+
memcpy(refspec, "+refs/heads/.:refs/incrypt/......................................../1/.", 14+GIT_SHA1_HEXSZ+14+4);
360+
refspec[12] = refspec[70] = pattern;
361+
memcpy(refspec + 14, prefix, GIT_SHA1_HEXSZ + 14);
362+
363+
strvec_pushl(&cmd.args, "fetch", verbosityflags[options.verbosity],
364+
progressflags[options.progress], "--no-write-fetch-head",
365+
"-p", url, refspec, NULL);
366+
367+
cmd.git_cmd = 1;
368+
//This causes a crash! : cmd.close_object_store = 1;
369+
/*return*/ run_command(&cmd);
370+
}
371+
350372
int cmd_main(int argc, const char** argv) {
351373
(void)argv;
352374
(void)argc;

0 commit comments

Comments
 (0)