def with_rw_repo(working_tree_ref, bare=False):
 assert isinstance(working_tree_ref, string_types), 'Decorator requires ref name for working tree checkout'
 def argument_passer(func):
  @wraps(func)
  def repo_creator(self):
   prefix = 'non_'
   if bare:
    prefix = ''
   repo_dir = tempfile.mktemp(prefix=('%sbare_%s' % (prefix, func.__name__)))
   rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=bare, n=True)
   rw_repo.head.commit = rw_repo.commit(working_tree_ref)
   if (not bare):
    rw_repo.head.reference.checkout()
   prev_cwd = os.getcwd()
   os.chdir(rw_repo.working_dir)
   try:
    return func(self, rw_repo)
   except:
    log.info('Keeping repo after failure: %s', repo_dir)
    repo_dir = None
    raise
   finally:
    os.chdir(prev_cwd)
    rw_repo.git.clear_cache()
    rw_repo = None
    import gc
    gc.collect()
    if (repo_dir is not None):
     rmtree(repo_dir)
  return repo_creator
 return argument_passer

def with_rw_repo ( working_tree_ref , bare = False ) : assert isinstance ( working_tree_ref , string_types ) , 'Decorator requires ref name for working tree checkout' def argument_passer ( func ) : @ wraps ( func ) def repo_creator ( self ) : prefix = 'non_' if bare : prefix = '' repo_dir = tempfile . mktemp ( prefix = ( '%sbare_%s' % ( prefix , func . __name__ ) ) ) rw_repo = self . rorepo . clone ( repo_dir , shared = True , bare = bare , n = True ) rw_repo . head . commit = rw_repo . commit ( working_tree_ref ) if ( not bare ) : rw_repo . head . reference . checkout ( ) prev_cwd = os . getcwd ( ) os . chdir ( rw_repo . working_dir ) try : return func ( self , rw_repo ) except : log . info ( 'Keeping repo after failure: %s' , repo_dir ) repo_dir = None raise finally : os . chdir ( prev_cwd ) rw_repo . git . clear_cache ( ) rw_repo = None import gc gc . collect ( ) if ( repo_dir is not None ) : rmtree ( repo_dir ) return repo_creator return argument_passer
same as with_bare_repo .