From e3eddae382686d29f9a9dde7358cdb5efd36cc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= Date: Sat, 7 Jun 2025 09:48:21 +0200 Subject: [PATCH 1/2] astextplain: use mimetype to decide helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use the file extension to determine which helper to call to convert a file to text. We currently match an all upper case version and an all lower case version of each extension, but sometimes variations like 'foo.Rtf' fall though our raster. To cover all variations in this established way we'd have to add every permutation of upper and lower case for each extension to the script. That's a big maintainance burden. We could also convert the passed filename to a known case and match against that. Since POSIX has no easy way for sh to do case conversion in-process we'd have to shell out to tr, awk or similar. For the antiword helper we already need to make sure the file is of the type it claims by it's extension. We use file to tell us the mimetype for this. file can also tell us the types of other files we care about for astextplain, so we can use it for the decision which helper to use in the first place. This fixes https://github.com/git-for-windows/git/issues/5641 Signed-off-by: Matthias Aßhauer --- git-extra/PKGBUILD | 4 ++-- git-extra/astextplain | 21 +++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/git-extra/PKGBUILD b/git-extra/PKGBUILD index 85f67ca21b..39f1c177db 100644 --- a/git-extra/PKGBUILD +++ b/git-extra/PKGBUILD @@ -5,7 +5,7 @@ pkgbase="mingw-w64-${_realname}" pkgname=($_realname "${MINGW_PACKAGE_PREFIX}-${_realname}") _ver_base=1.1 -pkgver=1.1.657.d7f05a9c2 +pkgver=1.1.658.f3272c147 pkgrel=1 pkgdesc="Git for Windows extra files" arch=('any') @@ -79,7 +79,7 @@ sha256sums=('8ed76d1cb069ac8568f21c431f5e23caebea502d932ab4cdff71396f4f0d5b72' 'dcbd1b981d5b899afe30151a5f5a27ea52025ff1335f131af1b5891f62ddd55b' '683ab066be19cb4defec470ebd53f165ca5dbf761fd40c13aee8abe31ba42803' '1cf2c13fb97c51375a76ed479362c3cbcdb51ab4d3a745e8d2c3a780badd8d46' - '201fc40c1aadadceccc617511a4add05536b3638bff34456cc334e3b21c130e7' + '2ad7292f8ea4aa7d027221bff2a987ad8e7c72a6866a5f14ea67f6187e850244' '180e05c1b8afa34d59cb2f6635bc75fece10474f37e164ea5916a6b3b56e20dd' '22f41610dea842890955032af30efdb60e80f310e95a04e57ab36b10e0376923' '38c0cf57e03d275cdd42984f102bee8352fac672f875ab23c46b9625eefc49f3' diff --git a/git-extra/astextplain b/git-extra/astextplain index be82357d12..ac5ab42390 100755 --- a/git-extra/astextplain +++ b/git-extra/astextplain @@ -7,28 +7,21 @@ if test "$#" != 1 ; then fi # XXX output encoding (UTF-8) hardcoded -case "$1" in - *.ods | *.ODS | *.odf |*.ODF | *.odt | *.ODT) +case "$(file --brief --mime-type "$1")" in + application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.formula | application/vnd.oasis.opendocument.text) odt2txt "$1" || cat "$1" ;; - *.doc | *.DOC | *.dot | *.DOT) - case "$(file --brief --mime-type "$1")" in - application/msword) - out=$(antiword -m UTF-8 "$1") && sed "s/\^M$//" <<<$out || cat "$1" - ;; - *) - cat "$1" - ;; - esac + application/msword) + out=$(antiword -m UTF-8 "$1") && sed "s/\^M$//" <<<$out || cat "$1" ;; - *.docx | *.DOCX | *.dotx | *.DOTX | *.docm | *.DOCM | *.dotm | *.DOTM) + application/vnd.openxmlformats-officedocument.wordprocessingml.* | application/vnd.ms-word.*.macroenabled.12) docx2txt.pl "$1" - || cat "$1" ;; - *.pdf | *.PDF) + application/pdf) out=$(pdftotext -q -layout -enc UTF-8 "$1" -) && sed "s/(\^M$)|(^\^L)//" <<<$out || cat "$1" ;; # TODO add rtf support - *.rtf | *.RTF) + application/rtf | text/rtf) cat "$1" ;; *) From 93430405fbc61e2f3cad0b70955b77f2b7515f3f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 9 Jun 2025 06:59:19 +0000 Subject: [PATCH 2/2] git-extra: update checksums Signed-off-by: Johannes Schindelin --- git-extra/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-extra/PKGBUILD b/git-extra/PKGBUILD index 39f1c177db..e8696f88b8 100644 --- a/git-extra/PKGBUILD +++ b/git-extra/PKGBUILD @@ -5,7 +5,7 @@ pkgbase="mingw-w64-${_realname}" pkgname=($_realname "${MINGW_PACKAGE_PREFIX}-${_realname}") _ver_base=1.1 -pkgver=1.1.658.f3272c147 +pkgver=1.1.659.e3eddae38 pkgrel=1 pkgdesc="Git for Windows extra files" arch=('any')