Skip to content

Commit ae02940

Browse files
committed
store url
1 parent 4f87117 commit ae02940

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

git-incrypt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ plugin.encryptrefname.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
4545
plugin.decryptrefname.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
4646
plugin.set_option.argtypes = [ctypes.c_char_p, ctypes.c_size_t,
4747
ctypes.c_char_p]
48+
plugin.geturl.restype = ctypes.c_char_p
4849
plugin.hashdata.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p]
4950
plugin.hashdatahex.argtypes = [ctypes.c_void_p, ctypes.c_size_t]
5051
plugin.hashdatahex.restype = ctypes.c_char_p
52+
plugin.globalinit.argtypes = [ctypes.c_char_p]
5153

5254
if not hasattr(pygit2.enums, 'FileMode'):
5355
class FileMode(enum.IntFlag):
@@ -160,21 +162,19 @@ class CryptRepo:
160162

161163
def __init__(self, clearname, url, init=None, forcetrust=False):
162164
assert clearname, 'This does not work yet outside a git repository'
163-
plugin.globalinit()
164-
self.prefix = f'refs/incrypt/{sha1hex(url.encode("utf-8"))}/'
165-
self.url = url
165+
plugin.globalinit(url.encode('utf-8'))
166+
self.prefix = f'refs/incrypt/{sha1hex(plugin.geturl())}/'
166167
if init:
167168
self.repo = pygit2.init_repository(clearname, bare=True)
168169
template = self._mktemplate(init.name, init.email,
169170
init.date, init.m)
170-
self.meta = MetaData(self.repo, self.url, self.prefix + '1/').init(
171+
self.meta = MetaData(self.repo, self.prefix + '1/').init(
171172
init.keys, template, 'refs/heads/master')
172173
self.trust(force=True, sign=True)
173174
else:
174175
self.repo = pygit2.Repository(clearname)
175176
self._fetch('_')
176-
self.meta = MetaData(self.repo, self.url,
177-
self.prefix + '1/').read()
177+
self.meta = MetaData(self.repo, self.prefix + '1/').read()
178178
if forcetrust:
179179
self.trust(force=forcetrust)
180180

@@ -249,7 +249,7 @@ class CryptRepo:
249249
['git', 'fetch',
250250
CryptRepo.verbosityflags[plugin.getverbosity()],
251251
'--progress' if plugin.getprogress() else '--no-progress',
252-
'--no-write-fetch-head', '-p', self.url,
252+
'--no-write-fetch-head', '-p', plugin.geturl().decode('utf-8'),
253253
f'+refs/heads/{pattern}:{self.prefix}1/{pattern}'],
254254
cwd=self.repo.path, check=True, stdout=sys.stderr)
255255

@@ -392,7 +392,8 @@ class CryptRepo:
392392
['--progress' if plugin.getprogress()
393393
else '--no-progress', '--porcelain'] +
394394
(['--atomic'] if plugin.getatomic() else []) +
395-
[self.url, '+' + self.prefix + '1/_:' + MetaData.REFNAME] +
395+
[plugin.geturl().decode('utf-8'), '+' +
396+
self.prefix + '1/_:' + MetaData.REFNAME] +
396397
[r[3] for r in xrefs],
397398
cwd=self.repo.path, check=False, text=True,
398399
stdout=subprocess.PIPE,
@@ -469,9 +470,8 @@ class MetaData:
469470
KEYVER = b'AES-256-CBC+IV'
470471
REFNAME = 'refs/heads/_'
471472

472-
def __init__(self, repo, url, prefix):
473+
def __init__(self, repo, prefix):
473474
self.repo = repo
474-
self.url = url
475475
self.prefix = prefix
476476
self.files = None
477477
self.key = None
@@ -483,7 +483,7 @@ class MetaData:
483483
def _gpg(self, args, inp):
484484
'run gpg'
485485
return subprocess.check_output(
486-
[f'gpg@incrypt::{self.url}'] + args,
486+
[f'gpg@incrypt::{plugin.geturl().decode("utf-8")}'] + args,
487487
executable='gpg', input=inp)
488488

489489
def init(self, gpgkeys, template, defaultbranch):

incrypt-plugin.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
#include "hash.h"
1313
#include "hex.h"
1414

15-
void globalinit(void);
15+
void globalinit(const char* url_arg);
1616
int set_option(const char *name, size_t namelen, const char *value);
1717
int getverbosity(void);
1818
int getprogress(void);
1919
int getatomic(void);
20+
const char* geturl(void);
2021
void setcryptkey(const unsigned char* k);
2122
unsigned char* encryptdata(const unsigned char* input, size_t inputlen,
2223
unsigned char* output, size_t* outputlen);
@@ -35,10 +36,15 @@ struct options {
3536
};
3637
static struct options options;
3738

38-
void globalinit(void) {
39+
static char* url = NULL;
40+
41+
void globalinit(const char* url_arg) {
42+
size_t urllen = strlen(url_arg);
3943
options.verbosity = 1;
4044
options.progress = !!isatty(2);
4145
options.atomic = 0;
46+
url = malloc(urllen + 1);
47+
memcpy(url, url_arg, urllen + 1);
4248
}
4349

4450
/*static*/ int set_option(const char *name, size_t namelen, const char *value)
@@ -90,6 +96,10 @@ int getatomic(void)
9096
return options.atomic;
9197
}
9298

99+
const char* geturl(void) {
100+
return url;
101+
}
102+
93103
static unsigned char key[48];
94104

95105
void setcryptkey(const unsigned char* k) {

0 commit comments

Comments
 (0)