3 # Creates a release tarball directly from git
5 # Note that the tarball contents might not exactly match
6 # a particular git commit, particularly for untagged
9 # An alternative approach would be to generate source tarballs
10 # using CPack. That would remove our dependency on git, but if
11 # Autotools is any indication it would require continuous
14 # Copyright 2011 Balint Reczey <balint@balintreczey.hu>
16 # Wireshark - Network traffic analyzer
17 # By Gerald Combs <gerald@wireshark.org>
18 # Copyright 1998 Gerald Combs
20 # SPDX-License-Identifier: GPL-2.0-or-later
26 while getopts "d:" OPTCHAR
; do
29 *) printf "Unknown option %s\n" "$OPTCHAR" ;;
32 shift $
(( OPTIND
- 1 ))
34 # The remaining parameter, if set, is a package version such as 3.4.5
35 # or 3.4.5-67-gabcd4321
36 # By default the version from make-version.py + CMake is used.
37 PROJECT_VERSION
=@PROJECT_VERSION@
38 if test -n "${1-}"; then
42 TARBALL
="${DESTDIR}/wireshark-${PROJECT_VERSION}.tar.zst"
44 # A tarball produced by 'git archive' will have the $Format string
45 # substituted due to the use of 'export-subst' in .gitattributes.
46 # shellcheck disable=SC2016
49 if [[ $COMMIT != \
$F* ]] ; then
50 # This file was extracted from a tarball produced by git archive
51 # and so we are not in a git repository.
52 if [[ -f "$TARBALL" ]] ; then
53 # git get-tar-commit-id works outside a git repo, as it
54 # only reads the first 1024 bytes of the tar extended header.
55 if [[ $
(git get-tar-commit-id
< <(zstdcat
"$TARBALL")) == "$COMMIT" ]] ; then
56 echo "$TARBALL commit ID matches $COMMIT."
58 # Allow people to make changes to a downloaded source tarball
60 echo "WARNING: $TARBALL is not the original git archive."
66 echo "The build system cannot produce a source tarball outside of a git repository."
67 echo "If you are trying to build an RPM package from source extracted from a tarball,"
68 echo "copy it (i.e., wireshark-${PROJECT_VERSION}.tar.zst) to"
70 echo "and run the build command again."
75 STASH_ID
=$
(git stash create ||
echo "")
77 if [[ -n "$STASH_ID" ]] ; then
78 echo "Setting commit from stash $STASH_ID"
81 echo "Setting commit from HEAD"
85 if [ -f "$TARBALL" ] ; then
86 printf "Found %s\\n" "$TARBALL"
87 if TARBALL_ID
=$
(git get-tar-commit-id
< <(zstdcat
"$TARBALL")) && COMMIT_ID
=$
(git rev-parse
--verify "$COMMIT") ; then
88 if [[ $TARBALL_ID == "$COMMIT_ID" ]] ; then
89 echo "$TARBALL commit ID matches $COMMIT."
95 echo "Creating $TARBALL from $COMMIT"
97 git archive
--prefix="wireshark-${PROJECT_VERSION}/" "$COMMIT" | zstd
--threads=0 --long --ultra -22 > "$TARBALL"