From: Michal Sojka Date: Fri, 11 Sep 2015 13:57:26 +0000 (+0200) Subject: Add git-ls-files-attr script X-Git-Tag: eaton-0.7~5 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/commitdiff_plain/b9c14221d9d95c415ea02c0ba34dbf87d90ddbaf Add git-ls-files-attr script Use this script in makefiles where we used custom shell code before. --- diff --git a/Makefile b/Makefile index 62551c7..16188fe 100644 --- 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 diff --git a/common.mk b/common.mk index 21be655..ef9dcf8 100644 --- 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,) diff --git a/etc/git-ls-files-attr b/etc/git-ls-files-attr new file mode 100755 index 0000000..7995b11 --- /dev/null +++ b/etc/git-ls-files-attr @@ -0,0 +1,31 @@ +#!/bin/sh + +usage() { echo >&2 "Usage: $0 [ --not ] [ --set | --unset | --unspecified ] ..."; } + +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