@@ -48,9 +48,15 @@ plugin.set_option.argtypes = [ctypes.c_char_p, ctypes.c_size_t,
4848plugin .geturl .restype = ctypes .c_char_p
4949plugin .getprefix .restype = ctypes .c_char_p
5050plugin .hashdata .argtypes = [ctypes .c_void_p , ctypes .c_size_t , ctypes .c_void_p ]
51- plugin .hashdatahex .argtypes = [ctypes .c_void_p , ctypes .c_size_t , ctypes .c_char_p ]
51+ plugin .hashdatahex .argtypes = [ctypes .c_void_p , ctypes .c_size_t ,
52+ ctypes .c_char_p ]
5253plugin .hashdatahex .restype = ctypes .c_char_p
53- plugin .globalinit .argtypes = [ctypes .c_char_p ]
54+ plugin .globalinit .argtypes = [ctypes .c_char_p , ctypes .c_char_p ]
55+ plugin .initbare .argtypes = [ctypes .c_char_p ]
56+ plugin .mktemplate .argtypes = [ctypes .c_char_p , ctypes .c_char_p ,
57+ ctypes .c_char_p , ctypes .c_char_p ,
58+ ctypes .c_char_p ]
59+ plugin .mktemplate .restype = ctypes .c_char_p
5460
5561if not hasattr (pygit2 .enums , 'FileMode' ):
5662 class FileMode (enum .IntFlag ):
@@ -157,44 +163,30 @@ class CryptRepo:
157163
158164 def __init__ (self , clearname , url , init = None , forcetrust = False ):
159165 assert clearname , 'This does not work yet outside a git repository'
160- plugin .globalinit (url .encode ('utf-8' ))
166+ plugin .globalinit (clearname . encode ( 'utf-8' ), url .encode ('utf-8' ))
161167 if init :
162- self .repo = pygit2 .init_repository (clearname , bare = True )
163- template = self ._mktemplate (init .name , init .email ,
164- init .date , init .m )
168+ plugin .initbare (clearname .encode ('utf-8' ))
169+ output = ctypes .create_string_buffer (41 )
170+ poutput = ctypes .c_char_p (ctypes .addressof (output ))
171+ plugin .mktemplate (
172+ init .name .encode ('utf-8' ) if init .name else None ,
173+ init .email .encode ('utf-8' ) if init .email else None ,
174+ init .date .encode ('utf-8' ) if init .date else None ,
175+ '\n \n ' .join (init .m ).encode ('utf-8' ) if init .m else None ,
176+ poutput )
177+ self .repo = pygit2 .Repository ('.' )
178+ template = self .repo .get (
179+ output .value .decode ('utf-8' )).read_raw ().split (b'\n ' , 1 )[1 ]
165180 self .meta = MetaData (self .repo ).init (
166181 init .keys , template , 'refs/heads/master' )
167182 self .trust (force = True , sign = True )
168183 else :
169- self .repo = pygit2 .Repository (clearname )
184+ self .repo = pygit2 .Repository ('.' )
170185 self ._fetch ('_' )
171186 self .meta = MetaData (self .repo ).read ()
172187 if forcetrust :
173188 self .trust (force = forcetrust )
174189
175- def _mktemplate (self , name , email , date , messages ):
176- 'create a template commit'
177- if not messages :
178- messages = ['Encrypted by git-incrypt.' ,
179- 'https://github.com/schiele/git-incrypt' ]
180- env = os .environ .copy ()
181- if name :
182- env ['GIT_AUTHOR_NAME' ] = name
183- env ['GIT_COMMITTER_NAME' ] = name
184- if email :
185- env ['GIT_AUTHOR_EMAIL' ] = email
186- env ['GIT_COMMITTER_EMAIL' ] = email
187- if date :
188- env ['GIT_AUTHOR_DATE' ] = date
189- env ['GIT_COMMITTER_DATE' ] = date
190- templateid = subprocess .check_output (
191- ['git' , 'commit-tree' ] +
192- [x for m in messages for x in ('-m' , m )] +
193- ['4b825dc642cb6eb9a060e54bf8d69288fbee4904' ],
194- cwd = self .repo .path , env = env ).decode ('utf-8' ).strip ()
195- template = self .repo .get (templateid ).read_raw ().split (b'\n ' , 1 )[1 ]
196- return template
197-
198190 def _progress_for (self , what , iterable , function ):
199191 'iterate over iterable and show progress'
200192 def update ():
@@ -244,7 +236,8 @@ class CryptRepo:
244236 CryptRepo .verbosityflags [plugin .getverbosity ()],
245237 '--progress' if plugin .getprogress () else '--no-progress' ,
246238 '--no-write-fetch-head' , '-p' , plugin .geturl ().decode ('utf-8' ),
247- f'+refs/heads/{ pattern } :{ plugin .getprefix ().decode ("utf-8" )} 1/{ pattern } ' ],
239+ f'+refs/heads/{ pattern } :{
240+ plugin .getprefix ().decode ("utf-8" )} 1/{ pattern } ' ],
248241 cwd = self .repo .path , check = True , stdout = sys .stderr )
249242
250243 def trust (self , force = False , sign = False ):
@@ -289,8 +282,10 @@ class CryptRepo:
289282 refs = [[r [0 ], plugin .getprefix ().decode ('utf-8' ) + '0/' + r [0 ],
290283 self .repo .revparse_single (r [1 ])]
291284 for r in [[decryptrefname (r , self .meta .key ), r ] for r in
292- filter (lambda r : len (r ) > len (plugin .getprefix ().decode ('utf-8' ))+ 3 and
293- r .startswith (plugin .getprefix ().decode ('utf-8' ) + '1/' ),
285+ filter (lambda r : len (r ) >
286+ len (plugin .getprefix ().decode ('utf-8' ))+ 3 and
287+ r .startswith (plugin .getprefix ().
288+ decode ('utf-8' ) + '1/' ),
294289 self .repo .references )]]
295290 cryptmap = self .meta .readmap (reverse = True )
296291 self ._progress_for (
@@ -307,8 +302,9 @@ class CryptRepo:
307302 for r in self .repo .references :
308303 if r .startswith (plugin .getprefix ().decode ('utf-8' ) + '0/' ):
309304 if r in expected :
310- result .append ([r [len (plugin .getprefix ().decode ('utf-8' ))+ 2 :],
311- self .repo .lookup_reference (r ).target ])
305+ result .append (
306+ [r [len (plugin .getprefix ().decode ('utf-8' ))+ 2 :],
307+ self .repo .lookup_reference (r ).target ])
312308 else :
313309 self .repo .references .delete (r )
314310 return result
@@ -353,7 +349,8 @@ class CryptRepo:
353349 else [cryptmap [str (obj .target )]])
354350
355351 xrefs = [[r [0 ], r [1 ], r [3 ], ('+' if r [2 ] else '' ) +
356- (plugin .getprefix ().decode ('utf-8' ) + '1/' + r [3 ] if r [0 ] else '' ) +
352+ (plugin .getprefix ().decode ('utf-8' ) + '1/' +
353+ r [3 ] if r [0 ] else '' ) +
357354 ':refs/heads/' + r [3 ],
358355 self .repo .revparse_single (r [0 ]) if r [0 ] else None ]
359356 for r in [[r [0 ], r [1 ], r [2 ],
@@ -372,11 +369,12 @@ class CryptRepo:
372369 for r in xrefs :
373370 if r [4 ]:
374371 self .repo .create_reference (
375- plugin .getprefix ().decode ('utf-8' ) + '1/' + r [2 ], cryptmap [ str ( r [ 4 ]. id )],
376- force = True )
372+ plugin .getprefix ().decode ('utf-8' ) + '1/' + r [2 ],
373+ cryptmap [ str ( r [ 4 ]. id )], force = True )
377374 else :
378375 try :
379- self .repo .references .delete (plugin .getprefix ().decode ('utf-8' ) + '1/' + r [2 ])
376+ self .repo .references .delete (
377+ plugin .getprefix ().decode ('utf-8' ) + '1/' + r [2 ])
380378 except KeyError :
381379 pass
382380 resdict = {}
@@ -388,7 +386,8 @@ class CryptRepo:
388386 else '--no-progress' , '--porcelain' ] +
389387 (['--atomic' ] if plugin .getatomic () else []) +
390388 [plugin .geturl ().decode ('utf-8' ), '+' +
391- plugin .getprefix ().decode ('utf-8' ) + '1/_:' + MetaData .REFNAME ] +
389+ plugin .getprefix ().decode ('utf-8' ) + '1/_:' +
390+ MetaData .REFNAME ] +
392391 [r [3 ] for r in xrefs ],
393392 cwd = self .repo .path , check = False , text = True ,
394393 stdout = subprocess .PIPE ,
@@ -512,7 +511,8 @@ class MetaData:
512511 def read (self ):
513512 'read the metadata'
514513 self .files = {}
515- tree = self .repo .revparse_single (plugin .getprefix ().decode ('utf-8' ) + '1/_' ).tree
514+ tree = self .repo .revparse_single (
515+ plugin .getprefix ().decode ('utf-8' ) + '1/_' ).tree
516516 obj = tree ['ver' ]
517517 self .files ['ver' ] = obj .id
518518 data = obj .read_raw ()
@@ -604,16 +604,19 @@ class MetaData:
604604 mapfile = self .repo .create_blob (encryptdata (
605605 sha1 (rawdata ) + rawdata , self .key ))
606606 collector .insert ('map' , mapfile , pygit2 .enums .FileMode .BLOB )
607- readmefile = self .repo .create_blob (ctypes .c_char_p .in_dll (plugin , 'CRYPTREADME' ).value )
607+ readmefile = self .repo .create_blob (
608+ ctypes .c_char_p .in_dll (plugin , 'CRYPTREADME' ).value )
608609 collector .insert ('README.md' , readmefile , pygit2 .enums .FileMode .BLOB )
609610 colid = collector .write ()
610611 commit = self .secretcommit (colid , [])
611- self .repo .create_reference (plugin .getprefix ().decode ('utf-8' ) + '1/_' , commit , force = True )
612+ self .repo .create_reference (
613+ plugin .getprefix ().decode ('utf-8' ) + '1/_' , commit , force = True )
612614 return self
613615
614616 def readmap (self , reverse = False ):
615617 'read the mapping table'
616- tree = self .repo .revparse_single (plugin .getprefix ().decode ('utf-8' ) + '1/_' ).tree
618+ tree = self .repo .revparse_single (
619+ plugin .getprefix ().decode ('utf-8' ) + '1/_' ).tree
617620 o = 20 if reverse else 0
618621 processed = {}
619622 rawdata = decryptdata (tree ['map' ].read_raw (), self .key )
0 commit comments