def commit_tree(object_store, blobs):
 trees = {'': {}}
 def add_tree(path):
  if (path in trees):
   return trees[path]
  (dirname, basename) = pathsplit(path)
  t = add_tree(dirname)
  assert isinstance(basename, bytes)
  newtree = {}
  t[basename] = newtree
  trees[path] = newtree
  return newtree
 for (path, sha, mode) in blobs:
  (tree_path, basename) = pathsplit(path)
  tree = add_tree(tree_path)
  tree[basename] = (mode, sha)
 def build_tree(path):
  tree = Tree()
  for (basename, entry) in trees[path].items():
   if isinstance(entry, dict):
    mode = stat.S_IFDIR
    sha = build_tree(pathjoin(path, basename))
   else:
    (mode, sha) = entry
   tree.add(basename, mode, sha)
  object_store.add_object(tree)
  return tree.id
 return build_tree('')

def commit_tree ( object_store , blobs ) : trees = { '' : { } } def add_tree ( path ) : if ( path in trees ) : return trees [ path ] ( dirname , basename ) = pathsplit ( path ) t = add_tree ( dirname ) assert isinstance ( basename , bytes ) newtree = { } t [ basename ] = newtree trees [ path ] = newtree return newtree for ( path , sha , mode ) in blobs : ( tree_path , basename ) = pathsplit ( path ) tree = add_tree ( tree_path ) tree [ basename ] = ( mode , sha ) def build_tree ( path ) : tree = Tree ( ) for ( basename , entry ) in trees [ path ] . items ( ) : if isinstance ( entry , dict ) : mode = stat . S_IFDIR sha = build_tree ( pathjoin ( path , basename ) ) else : ( mode , sha ) = entry tree . add ( basename , mode , sha ) object_store . add_object ( tree ) return tree . id return build_tree ( '' )
create a new commit object .