From 54eca7a5a4c2fcc670f6cc7e420677bbc417dd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Wed, 22 Apr 2020 20:59:26 +0700 Subject: [PATCH 1/6] xbps-src: use $XBPS_GIT_CMD for git --- common/environment/setup/git.sh | 18 ++++++++---------- .../hooks/post-install/05-generate-gitrevs.sh | 12 ++++-------- xbps-src | 5 ++--- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/common/environment/setup/git.sh b/common/environment/setup/git.sh index 870fa984e05..a2f7f0a28ee 100644 --- a/common/environment/setup/git.sh +++ b/common/environment/setup/git.sh @@ -1,19 +1,17 @@ # If XBPS_USE_BUILD_MTIME is enabled in conf file don't continue. # only run this, if SOURCE_DATE_EPOCH isn't set. + +if [ -z "$XBPS_GIT_CMD" ]; then + msg_error "BUG: environment/setup: XBPS_GIT_CMD is not set\n" +fi + if [ -n "$XBPS_USE_BUILD_MTIME" ]; then unset SOURCE_DATE_EPOCH - return 0 -fi -if [ -z "${SOURCE_DATE_EPOCH}" -a -n "$IN_CHROOT" ]; then - if command -v chroot-git &>/dev/null; then - GIT_CMD=$(command -v chroot-git) - elif command -v git &>/dev/null; then - GIT_CMD=$(command -v git) - fi +elif [ -z "${SOURCE_DATE_EPOCH}" -a -n "$IN_CHROOT" ]; then # check if the template is under version control: - if $GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} status -u normal --porcelain template | grep "^?? " &> /dev/null; then + if $XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} status -u normal --porcelain template | grep "^?? " &> /dev/null; then export SOURCE_DATE_EPOCH="$(stat -c %Y ${XBPS_SRCPKGDIR}/${basepkg}/template)" else - export SOURCE_DATE_EPOCH="$($GIT_CMD -C ${XBPS_DISTDIR} log --pretty='%ct' -n1 HEAD)" + export SOURCE_DATE_EPOCH="$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} log --pretty='%ct' -n1 HEAD)" fi fi diff --git a/common/hooks/post-install/05-generate-gitrevs.sh b/common/hooks/post-install/05-generate-gitrevs.sh index 82b2ab1a786..754ba8865b9 100644 --- a/common/hooks/post-install/05-generate-gitrevs.sh +++ b/common/hooks/post-install/05-generate-gitrevs.sh @@ -3,7 +3,7 @@ hook() { local GITREVS_FILE=${XBPS_STATEDIR}/gitrev - local GIT_CMD rev + local rev # If XBPS_USE_GIT_REVS is disabled in conf file don't continue. if [ -z $XBPS_USE_GIT_REVS ]; then @@ -14,16 +14,12 @@ hook() { return fi - if command -v chroot-git &>/dev/null; then - GIT_CMD=$(command -v chroot-git) - elif command -v git &>/dev/null; then - GIT_CMD=$(command -v git) - else - msg_error "$pkgver: cannot find chroot-git or git utility, exiting...\n" + if [ -z "$XBPS_GIT_CMD" ]; then + msg_error "BUG: post-install: XBPS_GIT_CMD is not set\n" fi cd $XBPS_SRCPKGDIR - rev="$($GIT_CMD rev-parse --short HEAD)" + rev="$($XBPS_GIT_CMD rev-parse --short HEAD)" echo "${sourcepkg}:${rev}" echo "${sourcepkg}:${rev}" > $GITREVS_FILE } diff --git a/xbps-src b/xbps-src index 459f27eb7b7..34c51bb182e 100755 --- a/xbps-src +++ b/xbps-src @@ -500,14 +500,13 @@ fi # Try using chroot-git then git from the host system if command -v chroot-git &>/dev/null; then - XBPS_GIT_CMD=$(command -v chroot-git) + export XBPS_GIT_CMD=$(command -v chroot-git) elif command -v git &>/dev/null; then - XBPS_GIT_CMD=$(command -v git) + export XBPS_GIT_CMD=$(command -v git) else echo "neither chroot-git or git are available in your system!" 1>&2 exit 1 fi -readonly XBPS_GIT_CMD if [ -n "$XBPS_HOSTDIR" ]; then export XBPS_REPOSITORY=$XBPS_HOSTDIR/binpkgs From 63edd0055d946a9c2f73eff4926272547c69d7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Mon, 20 Apr 2020 23:18:14 +0700 Subject: [PATCH 2/6] setup/git.sh: prefer git plumbing command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-ls-files(1) is plumbing command, its output will never change regardless of configuration, version. git-status(1) output will be changed depends on configuration. At least, 986d4dbc7d (common/environment/setup/git.sh: ensure untracked files are checked., 2017-11-24) was added to address a different output on `status.showUntrackedFiles`. By doing this, also reduce a pipe, and a fork-exec. Technically, git-log(1) is also a porcelain, but I _think_ `%ct` is stable enough to stay there. If the day has come, that `git-log(1)` can be replaced with: git cat-file commit HEAD | sed -ne '/^committer/{s/.* \([0-9]\+\) [-+][0-9][0-9][0-9][0-9]$/\1/p;q}' --- common/environment/setup/git.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/environment/setup/git.sh b/common/environment/setup/git.sh index a2f7f0a28ee..a7395ef53f3 100644 --- a/common/environment/setup/git.sh +++ b/common/environment/setup/git.sh @@ -9,7 +9,7 @@ if [ -n "$XBPS_USE_BUILD_MTIME" ]; then unset SOURCE_DATE_EPOCH elif [ -z "${SOURCE_DATE_EPOCH}" -a -n "$IN_CHROOT" ]; then # check if the template is under version control: - if $XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} status -u normal --porcelain template | grep "^?? " &> /dev/null; then + if [ -z "$($XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} ls-files template)" ]; then export SOURCE_DATE_EPOCH="$(stat -c %Y ${XBPS_SRCPKGDIR}/${basepkg}/template)" else export SOURCE_DATE_EPOCH="$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} log --pretty='%ct' -n1 HEAD)" From 318f29c7fc1373456c469c83f40429be85c32515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Tue, 21 Apr 2020 00:02:29 +0700 Subject: [PATCH 3/6] fixup??! setup/git.sh: prefer git plumbing command Technically, git-log(1) is also a porcelain, but I _think_ `%ct` is stable enough to stay there. If we chose to switch to all plumbing command, squash this change to previous change and update the commit message there. If we prefer to use git-log(1) instead, just drop this one. --- common/environment/setup/git.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/environment/setup/git.sh b/common/environment/setup/git.sh index a7395ef53f3..25cddf68e91 100644 --- a/common/environment/setup/git.sh +++ b/common/environment/setup/git.sh @@ -12,6 +12,7 @@ elif [ -z "${SOURCE_DATE_EPOCH}" -a -n "$IN_CHROOT" ]; then if [ -z "$($XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} ls-files template)" ]; then export SOURCE_DATE_EPOCH="$(stat -c %Y ${XBPS_SRCPKGDIR}/${basepkg}/template)" else - export SOURCE_DATE_EPOCH="$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} log --pretty='%ct' -n1 HEAD)" + export SOURCE_DATE_EPOCH="$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} cat-file commit HEAD | + sed -ne '/^committer/{s/.* \([0-9]\+\) [-+][0-9][0-9][0-9][0-9]$/\1/p;q}')" fi fi From e6896d263063a76e5ef5bc84337720451d4f8b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Tue, 21 Apr 2020 00:14:49 +0700 Subject: [PATCH 4/6] setup: export SOURCE_DATE_EPOCH from outside of chroot git-worktree(1), and Git shared repository can use a plain text file named `.git` at the root of working tree, containing `gitdir: ` to point to the real directory that has repository. See: gitrepository-layout(5). But, that directory is usually inaccessible inside chroot. In order to support git-worktree(1) and Git shared repository, compute SOURCE_DATE_EPOCH from outside of chroot, and the chroot will carry it over to inside chroot. I've only tested again xbps-uunshare(1). --- common/environment/setup/git.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/environment/setup/git.sh b/common/environment/setup/git.sh index 25cddf68e91..8a45c5dd28b 100644 --- a/common/environment/setup/git.sh +++ b/common/environment/setup/git.sh @@ -7,9 +7,12 @@ fi if [ -n "$XBPS_USE_BUILD_MTIME" ]; then unset SOURCE_DATE_EPOCH -elif [ -z "${SOURCE_DATE_EPOCH}" -a -n "$IN_CHROOT" ]; then +elif [ -z "${SOURCE_DATE_EPOCH}" ]; then + if [ -n "$IN_CHROOT" ]; then + msg_error "xbps-src's BUG: SOURCE_DATE_EPOCH is undefined\n" + fi # check if the template is under version control: - if [ -z "$($XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} ls-files template)" ]; then + if [ -n "$basepkg" -a -z "$($XBPS_GIT_CMD -C ${XBPS_SRCPKGDIR}/${basepkg} ls-files template)" ]; then export SOURCE_DATE_EPOCH="$(stat -c %Y ${XBPS_SRCPKGDIR}/${basepkg}/template)" else export SOURCE_DATE_EPOCH="$($XBPS_GIT_CMD -C ${XBPS_DISTDIR} cat-file commit HEAD | From e484779124be5a137137e47051cd4d95c25ad428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Tue, 21 Apr 2020 22:52:38 +0700 Subject: [PATCH 5/6] setup: compute gitrev from outside of chroot Together with previous commit, `xbps-src` is able to support git-worktree and shared repository by now. --- common/environment/setup/git.sh | 12 ++++++++++++ common/hooks/post-install/05-generate-gitrevs.sh | 10 ++++------ common/xbps-src/shutils/chroot.sh | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/common/environment/setup/git.sh b/common/environment/setup/git.sh index 8a45c5dd28b..8372461247e 100644 --- a/common/environment/setup/git.sh +++ b/common/environment/setup/git.sh @@ -19,3 +19,15 @@ elif [ -z "${SOURCE_DATE_EPOCH}" ]; then sed -ne '/^committer/{s/.* \([0-9]\+\) [-+][0-9][0-9][0-9][0-9]$/\1/p;q}')" fi fi + +# if XBPS_USE_GIT_REVS is enabled in conf file, +# compute XBPS_GIT_REVS to use in pkg hooks +if [ -z "$XBPS_USE_GIT_REVS" ]; then + unset XBPS_GIT_REVS +elif [ -z "$XBPS_GIT_REVS" ]; then + if [ -n "$IN_CHROOT" ]; then + msg_error "xbps-src's BUG: XBPS_GIT_REVS is undefined\n" + else + export XBPS_GIT_REVS="$($XBPS_GIT_CMD -C "${XBPS_DISTDIR}" rev-parse --verify --short HEAD)" + fi +fi diff --git a/common/hooks/post-install/05-generate-gitrevs.sh b/common/hooks/post-install/05-generate-gitrevs.sh index 754ba8865b9..c5a51f0d101 100644 --- a/common/hooks/post-install/05-generate-gitrevs.sh +++ b/common/hooks/post-install/05-generate-gitrevs.sh @@ -3,7 +3,6 @@ hook() { local GITREVS_FILE=${XBPS_STATEDIR}/gitrev - local rev # If XBPS_USE_GIT_REVS is disabled in conf file don't continue. if [ -z $XBPS_USE_GIT_REVS ]; then @@ -14,12 +13,11 @@ hook() { return fi - if [ -z "$XBPS_GIT_CMD" ]; then - msg_error "BUG: post-install: XBPS_GIT_CMD is not set\n" + if [ -z "$XBPS_GIT_REVS" ]; then + msg_error "BUG: XBPS_GIT_REVS is not set\n" fi cd $XBPS_SRCPKGDIR - rev="$($XBPS_GIT_CMD rev-parse --short HEAD)" - echo "${sourcepkg}:${rev}" - echo "${sourcepkg}:${rev}" > $GITREVS_FILE + echo "${sourcepkg}:${XBPS_GIT_REVS}" + echo "${sourcepkg}:${XBPS_GIT_REVS}" > $GITREVS_FILE } diff --git a/common/xbps-src/shutils/chroot.sh b/common/xbps-src/shutils/chroot.sh index 1298952fd40..436f8866cd4 100644 --- a/common/xbps-src/shutils/chroot.sh +++ b/common/xbps-src/shutils/chroot.sh @@ -175,6 +175,7 @@ chroot_handler() { ${HTTP_PROXY_AUTH:+HTTP_PROXY_AUTH="${HTTP_PROXY_AUTH}"} \ ${FTP_RETRIES:+FTP_RETRIES="${FTP_RETRIES}"} \ SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \ + XBPS_GIT_REVS="$XBPS_GIT_REVS" \ XBPS_ALLOW_CHROOT_BREAKOUT="$XBPS_ALLOW_CHROOT_BREAKOUT" \ $XBPS_COMMONDIR/chroot-style/${XBPS_CHROOT_CMD:=uunshare}.sh \ $XBPS_MASTERDIR $XBPS_DISTDIR "$XBPS_HOSTDIR" "$XBPS_CHROOT_CMD_ARGS" \ From 275e4938eddd15e3aa815bc2b26163fc9f759e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 26 Apr 2020 08:19:08 +0700 Subject: [PATCH 6/6] chroot-git: test new git info system --- srcpkgs/chroot-git/template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcpkgs/chroot-git/template b/srcpkgs/chroot-git/template index 03b79a9ccce..a71a0e62251 100644 --- a/srcpkgs/chroot-git/template +++ b/srcpkgs/chroot-git/template @@ -1,7 +1,7 @@ # Template file for 'chroot-git' pkgname=chroot-git version=2.26.2 -revision=1 +revision=2 bootstrap=yes wrksrc="git-${version}" build_style=gnu-configure