git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Ignore file filter
@ 2005-05-12 21:30 David Greaves
       [not found] ` <7v64xodshs.fsf@assigned-by-dhcp.cox.net>
  2005-05-13 23:12 ` Petr Baudis
  0 siblings, 2 replies; 18+ messages in thread
From: David Greaves @ 2005-05-12 21:30 UTC (permalink / raw)
  To: Petr Baudis, GIT Mailing Lists

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

Hi Petr

This is an inline filter that introduces the concept of .git/ignore
It is intended to be used within the cogito scripts like the other cg-X*
files.


Signed-off-by: David Greaves <david@dgreaves.com>

-- 


[-- Attachment #2: cg-Xignore --]
[-- Type: text/plain, Size: 2346 bytes --]

#!/usr/bin/env bash
#
# Takes a list of files on stdin and only passes valid ones agording to .git/ignore
# Copyright (c) David Greaves, 2005
#
# This filter implements cogito ignore rules and should typically be used in find pipelines
#
# Synopsis
# cg-Xignore [-debug] [-f] [-h] [-d] < file-list >useful-file-list
#
# Options
# -debug::
#     produce helpful debug output
#
# -q::
#     don't say what paths are ignored
#
# -f::
#     passes files
#
# -d::
#     passes directories
#
# -h::
#     passes symbolic links
#
# The default is to pass all file types that are not ignored.
#
# Note that the .git/ignore file contains multiple expressions, 1 per line
# Lines beginning with a '#' are ignored (allowing comments)
# These are 'bash regular expressions' not glob patterns
# This allows ignore rules to take the directory into account
# Suggested contents:
#   # bash regexps (not globs)
#   ^\.[^/]
#   /\.
#   /$
#   .*\.o$


# This doesn't allow the -h which is the [ arg for symlinks...
#. ${COGITO_LIB}cg-Xlib
_git=${GIT_DIR:-.git}

IGNORE_FILE="$_git/ignore"

if [ "$1" = "-0" ]; then
    # doesn't work :(
    zerosep=$'-d "\0"'
    shift
fi

# Defaults
pass_files=0
pass_dirs=0
pass_links=0
pass_all=1
while [ $# -gt 0 ]; do
    case $1 in
	"-f")
	    pass_all=0
	    pass_files=1
	    ;;
	"-d")
	    pass_all=0
	    pass_dirs=1
	    ;;
	"-h")
	    pass_all=0
	    pass_links=1
	    ;;
	"-q")
	    quiet=1
	    ;;
	"-debug")
	    debug=1
	    ;;
	esac
    shift
done

# save stderr
exec 5>&2
if [ $quiet ]; then
    # turn off noise
    exec 2>&-
fi

if [ $debug ]; then
    exec 4>&5
else
    exec 4>/dev/null
fi


# Strip out the common leading ./ allowing "find ."
sed 's:^./::' | \
while read $zerosep file; do
    echo "consider file: $file" >&4
    ignore=0
    if [ -f $IGNORE_FILE ]; then
	exec 3<$IGNORE_FILE
	while read -r -u3 patt ; do
	    if [[ $patt =~ "^\w*#" ]]; then
		continue
	    fi
	    echo "consider pattern: $patt" >&4
	    if [[ $file =~ $patt ]]; then
		ignore=1
		echo "Ignoring $file because of $patt" >&2
		break
	    fi
	done
    fi
    echo "passing file: $file" >&4
    
    if [ $ignore != "1" \
	-a \( $pass_all -eq 1 \
	   -o \( $pass_files -eq 1 -a -f $file \) \
	   -o \( $pass_dirs  -eq 1 -a -d $file \) \
	   -o \( $pass_links -eq 1 -a -h $file \) \
	   \) \
	]; then
	echo $file
    fi
done

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-05-16 16:23 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-12 21:30 [PATCH] Ignore file filter David Greaves
     [not found] ` <7v64xodshs.fsf@assigned-by-dhcp.cox.net>
2005-05-13  8:50   ` David Greaves
2005-05-13 23:12 ` Petr Baudis
2005-05-14  8:28   ` David Greaves
2005-05-14  9:01     ` Junio C Hamano
2005-05-14 14:24       ` Petr Baudis
2005-05-14 15:13         ` David Greaves
2005-05-14 15:30           ` [RFD] Ignore rules Petr Baudis
2005-05-14 17:51             ` David Greaves
2005-05-14 18:12             ` Junio C Hamano
2005-05-15  1:11               ` Jon Seymour
2005-05-15  6:05                 ` Junio C Hamano
2005-05-15  6:52                   ` Junio C Hamano
2005-05-15 20:27                   ` [RFD] git-run-with-user-path Junio C Hamano
2005-05-16  9:35                 ` [RFD] Ignore rules Matthias Urlichs
2005-05-16 16:05                   ` David Greaves
2005-05-14 12:21     ` [PATCH] Ignore file filter Petr Baudis
2005-05-14 14:28       ` David Greaves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).