]> git.wh0rd.org - home.git/blobdiff - .bin/git-repack
git-repack: clean empty dirs
[home.git] / .bin / git-repack
index d218a99944482f651032c924596f3172e2b18708..063ff81a8547f93e00cabd2524d2ad8278f019de 100755 (executable)
@@ -63,6 +63,7 @@ def readfile(path):
     """Read |path| and return its data"""
     if os.path.isfile(path):
         return open(path).read()
+    return ''
 
 
 def unlink(path):
@@ -141,11 +142,19 @@ def repack(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))