about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGonzalo Tornaría <tornaria@cmat.edu.uy>2022-02-20 11:54:01 -0300
committerLeah Neukirchen <leah@vuxu.org>2022-02-20 16:56:38 +0100
commit97b7b55dfdf2df95f37e46625202aa9a8cf1ffc8 (patch)
tree1e3a0b0094badbb4a98c79748eebfafe56c6cd72
parentd3b0cdd3b741bd7163f513bf10f97687bfb133ff (diff)
downloadxtools-97b7b55dfdf2df95f37e46625202aa9a8cf1ffc8.tar.gz
xtools-97b7b55dfdf2df95f37e46625202aa9a8cf1ffc8.tar.xz
xtools-97b7b55dfdf2df95f37e46625202aa9a8cf1ffc8.zip
xlint: improvements to lint from git index
 - do not leak $tmpfile in output from scan()
 - indent using tabs
 - add new options to README
-rw-r--r--README4
-rwxr-xr-xxlint15
-rw-r--r--xtools.112
3 files changed, 22 insertions, 9 deletions
diff --git a/README b/README
index 4a38bf1..a625c77 100644
--- a/README
+++ b/README
@@ -69,8 +69,10 @@ COMMANDS
      xlg pkg
         – open short commit log for XBPS template
 
-     xlint template | pkgname
+     xlint template | pkgname | :pkgname | :
         – scan XBPS template for common mistakes
+        - use ':pkgname' to lint template as staged in the git index
+        - use ':' to lint all templates staged in the git index
 
      xlocate
         [-g | -S | pattern] – locate files in all XBPS packages
diff --git a/xlint b/xlint
index 3c37558..191d51e 100755
--- a/xlint
+++ b/xlint
@@ -9,7 +9,7 @@ scan() {
 	local rx="$1" msg="$2"
 	grep -P -Hn -e "$rx" "$template" |
 		grep -v -P -e "[^:]*:[^:]*:\s*#" |
-		sed "s/^\([^:]*:[^:]*:\)\(.*\)/\1 $msg/"
+		sed "s/^[^:]*:\([^:]*\):\(.*\)/$argument:\1: $msg/"
 }
 
 once() {
@@ -349,19 +349,20 @@ void_packages="$(xdistdir 2>/dev/null)/"
 ret=0
 
 if [ "$1" = ":" ]; then
-    # get a list of all templates staged in the git index
+	# get a list of all templates staged in the git index
 	set -- $(git -C "$void_packages" diff --cached --name-only |
-        sed -ne 's|^srcpkgs/\([^/]*\)/template$|:\1|p')
+		sed -ne 's|^srcpkgs/\([^/]*\)/template$|:\1|p')
 fi
 
 for argument; do
 	template=
 	if [ -f "$argument" ]; then
 		template="$argument"
-    elif [ "${argument#:}" != "$argument" ]; then
+	elif [ "${argument#:}" != "$argument" ]; then
 		trap "rm -- ${tmpfile:=$(mktemp)}" EXIT INT TERM
-        git -C "$void_packages" show ":srcpkgs/${argument#:}/template" \
-            > ${template:=$tmpfile} || continue
+		# get template as staged in the git index
+		git -C "$void_packages" show ":srcpkgs/${argument#:}/template" \
+			> ${template:=$tmpfile} || continue
 	else
 		_template="${void_packages}srcpkgs/$argument/template"
 		[ -f "$_template" ] && template="$_template"
@@ -460,6 +461,6 @@ for argument; do
 	file_end
 	else
 	echo no such template "$argument" 1>&2
-	fi | sort -t: -n -k2 | grep . && ret=1
+	fi | sort -t: -n -k2 -k3 | grep . && ret=1
 done
 exit $ret
diff --git a/xtools.1 b/xtools.1
index 9f8c631..c2db90c 100644
--- a/xtools.1
+++ b/xtools.1
@@ -73,8 +73,18 @@ but take cwd repo and sudo/su into account
 .Nd list installed packages by install-date
 .It Nm xlg Ar pkg
 .Nd open short commit log for XBPS template
-.It Nm xlint Ar template | pkgname
+.It Nm xlint Ar template | pkgname | Cm \&: Ns Ar pkgname | Cm \&:
 .Nd scan XBPS template for common mistakes
+.Bl -dash -offset 0n -width 0n -compact
+.It
+use
+.Sq Cm \&: Ns Ar pkgname
+to lint template as staged in the git index
+.It
+use
+.Sq Cm \&:
+to lint all templates staged in the git index
+.El
 .It Nm xlocate
 .Oo
 .Fl g | S |