def hash_dir(path):
dir_hash = {}<EOL>for root, dirs, files in os.walk(path, topdown=False):<EOL><INDENT>f_hash = ((f, hash_file(join(root, f))) for f in files)<EOL>d_hash = ((d, dir_hash[join(root, d)]) for d in dirs)<EOL>dir_hash[join(*split(root))] = _mktree(f_hash, d_hash)<EOL><DEDENT>return dir_hash[path]<EOL>
Write directory at path to Git index, return its SHA1 as a string.