# [RFC/PATCH] git-repack: shortcut in case of just one pack, and no loose objects

1 messages from 2007-02-25 to 2007-02-25. Participants: Johannes Schindelin.
Thread: https://gitlist.dev/t/6943

## Johannes Schindelin, 2007-02-25 00:49

Subject: [RFC/PATCH] git-repack: shortcut in case of just one pack, and no loose objects
Message-ID: <Pine.LNX.4.63.0702250144530.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702250144530.22628%40wbgn013.biozentrum.uni-wuerzburg.de

```

When there is at most one pack, and there are no loose objects,
the result should be one pack _and_ reuse of deltas is allowed,
there is no need to repack, really.

The code does not check for *.keep files; they are either sign of
an ongoing repack, or of packs which do not matter for repacking
purposes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	I _think_ this is correct, but I might have missed something 
	obvious...

 git-repack.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/git-repack.sh b/git-repack.sh
index ddfa8b4..15094b3 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -25,6 +25,16 @@ do
 	shift
 done
 
+if test "z$all_into_one" = zt -a "z$no_reuse_delta" = z; then
+	# check if no loose objects are around, and only up to one pack
+	objdirs="$(ls "$GIT_DIR"/objects/?? 2>/dev/null)"
+	packs="$(cd "$GIT_DIR/objects/pack/"; ls *.pack 2>/dev/null)"
+	case "$objdirs,$packs" in
+	*.pack*.pack*) ;;
+	,*) echo "No need to repack" >&2; exit 0
+	esac
+fi
+
 # Later we will default repack.UseDeltaBaseOffset to true
 default_dbo=false
 
-- 
1.5.0.1.2390.g7757

```
