@@ -44,6 +44,7 @@ plugin.decryptdata.argtypes = [
4444 ctypes .c_void_p , ctypes .POINTER (ctypes .c_size_t )]
4545plugin .encryptrefname .argtypes = [ctypes .c_void_p , ctypes .c_void_p ]
4646plugin .decryptrefname .argtypes = [ctypes .c_void_p , ctypes .c_void_p ]
47+ plugin .set_option .argtypes = [ctypes .c_char_p , ctypes .c_size_t , ctypes .c_char_p ]
4748
4849if not hasattr (pygit2 .enums , 'FileMode' ):
4950 class FileMode (enum .IntFlag ):
@@ -144,12 +145,7 @@ class CryptRepo:
144145
145146 def __init__ (self , clearname , url , init = None , forcetrust = False ):
146147 assert clearname , 'This does not work yet outside a git repository'
147- self .settings = {
148- 'atomic' : False ,
149- 'progress' : True ,
150- 'verbosity' : 1 ,
151- 'followtags' : False
152- }
148+ plugin .globalinit ()
153149 hashstr = hashlib .sha1 (url .encode ('utf-8' )).hexdigest ()
154150 self .prefix = f'refs/incrypt/{ hashstr } /'
155151 self .url = url
@@ -195,7 +191,7 @@ class CryptRepo:
195191 'iterate over iterable and show progress'
196192 def update ():
197193 'update progress'
198- if self . settings [ 'progress' ] and total :
194+ if plugin . getprogress () and total :
199195 nonlocal progress
200196 progress += 1
201197 sys .stderr .write (f'\r remote: { what } '
@@ -208,7 +204,7 @@ class CryptRepo:
208204 update ()
209205 function (i )
210206 update ()
211- if self . settings [ 'progress' ] and total :
207+ if plugin . getprogress () and total :
212208 sys .stderr .write (', done.\n ' )
213209 sys .stderr .flush ()
214210
@@ -237,8 +233,8 @@ class CryptRepo:
237233 def _fetch (self , pattern ):
238234 subprocess .run (
239235 ['git' , 'fetch' ,
240- CryptRepo .verbosityflags [self . settings [ 'verbosity' ] ],
241- '--progress' if self . settings [ 'progress' ] else '--no-progress' ,
236+ CryptRepo .verbosityflags [plugin . getverbosity () ],
237+ '--progress' if plugin . getprogress () else '--no-progress' ,
242238 '--no-write-fetch-head' , '-p' , self .url ,
243239 f'+refs/heads/{ pattern } :{ self .prefix } 1/{ pattern } ' ],
244240 cwd = self .repo .path , check = True , stdout = sys .stderr )
@@ -377,16 +373,16 @@ class CryptRepo:
377373 resdict = {}
378374 for line in subprocess .run (
379375 ['git' , 'push' ] +
380- ([CryptRepo .verbosityflags [self . settings [ 'verbosity' ] ]]
381- if self . settings [ 'verbosity' ] > 1 else []) +
382- ['--progress' if self . settings [ 'progress' ]
376+ ([CryptRepo .verbosityflags [plugin . getverbosity () ]]
377+ if plugin . getverbosity () > 1 else []) +
378+ ['--progress' if plugin . getprogress ()
383379 else '--no-progress' , '--porcelain' ] +
384- (['--atomic' ] if self . settings [ 'atomic' ] else []) +
380+ (['--atomic' ] if plugin . getatomic () else []) +
385381 [self .url , '+' + self .prefix + '1/_:' + MetaData .REFNAME ] +
386382 [r [3 ] for r in xrefs ],
387383 cwd = self .repo .path , check = False , text = True ,
388384 stdout = subprocess .PIPE ,
389- stderr = sys .stderr if self . settings [ 'verbosity' ] > 1
385+ stderr = sys .stderr if plugin . getverbosity () > 1
390386 else subprocess .DEVNULL
391387 ).stdout .split ('\n ' ):
392388 e = line .split ('\t ' , 2 )
@@ -442,10 +438,7 @@ def remotehelperloop():
442438 elif command [0 ] == 'push' :
443439 pushcommand (line )
444440 elif command [0 ] == 'option' :
445- if command [1 ] in ['atomic' , 'progress' , 'verbosity' , 'followtags' ]:
446- crypt .settings [command [1 ]] = command [2 ] == 'true' \
447- if isinstance (crypt .settings [command [1 ]], bool ) \
448- else int (command [2 ])
441+ if plugin .set_option (command [1 ].encode ('utf-8' ), len (command [1 ].encode ('utf-8' )), command [2 ].encode ('utf-8' )):
449442 sys .stdout .write ('ok\n ' )
450443 else :
451444 sys .stdout .write ('unsupported\n ' )
0 commit comments