"""Read |path| and return its data"""
if os.path.isfile(path):
return open(path).read()
+ return ''
def unlink(path):
else:
rundir = path
+ cmd = ['git', '--git-dir', rundir, 'reflog', 'expire', '--all', '--stale-fix']
+ print('Cleaning reflog: %s' % ' '.join(cmd))
+ subprocess.check_call(cmd, cwd='/')
+
# This also packs refs/tags for us.
cmd = ['git', '--git-dir', rundir, 'gc', '--aggressive', '--prune=all']
print('Repacking git repo: %s' % ' '.join(cmd))
subprocess.check_call(cmd, cwd='/')
+ # Clean empty dirs.
+ cmd = ['find', rundir, '-depth', '-type', 'd', '-exec', 'rmdir', '{}', '+']
+ subprocess.call(cmd, stderr=open('/dev/null', 'w'))
+
if tmpdir:
cmd = ['rsync', '-a', '--delete', tmpdir + '/', path + '/']
print('Syncing back git repo: %s' % ' '.join(cmd))