Skip to content

Commit d2a9949

Browse files
use mktemp as tempfile is not available on macOS
1 parent 69f7245 commit d2a9949

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

git-find-large-files

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ OBJECTS=$(
3535
| sort -nr
3636
)
3737

38-
TMP=$(tempfile) || exit
39-
trap 'rm -f $TMP*' EXIT
38+
TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp/}git-find-large-files.XXXXXX") || exit
39+
trap "rm -rf $TMP_DIR" EXIT
4040

41-
git rev-list --all --objects > $TMP.objects
42-
git rev-list --all --objects --max-count=1 > $TMP.objects.1
41+
git rev-list --all --objects > $TMP_DIR/objects
42+
git rev-list --all --objects --max-count=1 > $TMP_DIR/objects.1
4343

4444
for OBJ in $OBJECTS; do
4545
# extract the compressed size in kilobytes
@@ -53,9 +53,9 @@ for OBJ in $OBJECTS; do
5353
SHA=$(echo $OBJ | cut -f 2 -d ' ')
5454

5555
# find the objects location in the repository tree
56-
LOCATION=$(grep $SHA $TMP.objects | sed "s/$SHA //")
56+
LOCATION=$(grep $SHA $TMP_DIR/objects | sed "s/$SHA //")
5757

58-
if grep $SHA $TMP.objects.1 >/dev/null; then
58+
if grep $SHA $TMP_DIR/objects.1 >/dev/null; then
5959
# Object is in the head revision
6060
HEAD="Present"
6161
elif [ -e $LOCATION ]; then
@@ -66,9 +66,9 @@ for OBJ in $OBJECTS; do
6666
HEAD="Deleted"
6767
fi
6868

69-
echo "$COMPRESSED_SIZE,$HEAD,$LOCATION" >> $TMP.output
69+
echo "$COMPRESSED_SIZE,$HEAD,$LOCATION" >> $TMP_DIR/output
7070
done
7171

72-
column -t -s ',' < $TMP.output
73-
rm -f $TMP*
72+
column -t -s ',' < $TMP_DIR/output
73+
rm -rf "$TMP_DIR"
7474
exit 0

0 commit comments

Comments
 (0)