]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Add git-ls-files-attr script
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 11 Sep 2015 13:57:26 +0000 (15:57 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 11 Sep 2015 13:57:26 +0000 (15:57 +0200)
Use this script  in makefiles where we used custom shell code before.

Makefile
common.mk
etc/git-ls-files-attr [new file with mode: 0755]

index 62551c761948f6fbbc88653bfea78352c4aa5b7a..16188fe1bcfc2684866b4672ddd5414e50c0a0a4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ subdir-build/%: print-targets
        $(MAKE) -C $(@:subdir-%=%) $(MAKECMDGOALS)
 
 
-UNCRUSTIFY_FILES = $(shell git ls-files|git check-attr --stdin uncrustify|awk -F: '/uncrustify: set$$/ {print $$1}')
+UNCRUSTIFY_FILES = $(shell etc/git-ls-files-attr uncrustify)
 UNCRUSTIFY_CFG = etc/uncrustify.cfg
 define UNCRUSTIFY_ALL
 $(foreach i,$(UNCRUSTIFY_FILES),git show HEAD:$i | uncrustify -c $(UNCRUSTIFY_CFG) -o $i
index 21be6551f7cd3d3a624e0998422a56dff090fbe8..ef9dcf858c81eb9a4195c1419d18a3541c4353e8 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -30,7 +30,7 @@ endif
 
 # `make release` can ignore files without certain git attribute
 RELEASE_IGNORE_FILES_CMD = $(strip $(if $(RELEASE_ATTR),\
-       git ls-files | git check-attr --stdin $(RELEASE_ATTR)|awk -F: '!/$(RELEASE_ATTR): set$$/ {print $$1}',\
+       etc/git-ls-files-attr --not $(RELEASE_ATTR),\
        $(if $(filter RELEASE_ATTR,$(.VARIABLES)),,$(error Please specify RELEASE_ATTR variable (it can be empty)))))
 
 # Usage: $(call release_rules,<release_prefix>)
diff --git a/etc/git-ls-files-attr b/etc/git-ls-files-attr
new file mode 100755 (executable)
index 0000000..7995b11
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+usage() { echo >&2 "Usage: $0 [ --not ] [ --set | --unset | --unspecified ] <attr> <ls-files args>..."; }
+
+state=set
+
+if test $1 = "--not"; then
+       not=true
+       shift
+else
+       not=false
+fi
+
+
+case $1 in
+    --set)         state=set;         shift;;
+    --unspecified) state=unspecified; shift;;
+    --unset)       state=unset;       shift;;
+    -*) usage; exit 1;;
+esac
+
+if test -z "$1"; then usage; exit 1; fi
+
+attr=$1
+shift
+
+git ls-files "$@" | git check-attr --stdin $attr | if $not; then
+       awk -F': ' -v state=$state '{ if ($3 != state) print $1 }'
+else
+       awk -F': ' -v state=$state '{ if ($3 == state) print $1 }'
+fi