[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] tiny addition to book

From: Archie Cobbs <archie_at_dellroad.org>
Date: 2004-06-16 17:15:15 CEST

Øyvind A. Holm wrote:
> On 2004-06-14 15:11-0500 Archie Cobbs wrote:
>
> > Also, I wrote a simple script that slurps in "mime.types" files (in
> > Apache httpd's format) and then scans a working hierarchy, setting
> > svn:mime-type for all files with recognized suffixes.. might be useful
> > for the SVN utilities project?
>
> Indeed, that sounds like a very useful script...

OK, you asked for it.. :-)

The bad news is that it's a pretty brain-dead shell script. I'm sure
there are some perl wizards who could compress this down to one line
and make it run more efficiently.

-Archie

__________________________________________________________________________
Archie Cobbs * CTO, Awarix * http://www.awarix.com

#!/bin/sh

#
# This script runs through all files in a hierarchy and sets the
# Subversion MIME type on all recognized file extensions.
# It takes one or more "mime.types" files as input, which are in
# the format of Apache's "mime.types" file.
#

scan_types()
{
    grep -v ^# "$1" \
      | awk '{ for (i=2; i<=NF; i++) printf "%s %s\n", $1, $i }' \
      | while read TYPE SUFFIX; do
        if [ "${SUFFIX}" = "$3" ]; then
            if [ "${QUIET}" != "true" ]; then
                echo svn propset -q svn:mime-type "${TYPE}" "$2"
            fi
            if [ "${DRYRUN}" != "true" ]; then
                svn propset -q svn:mime-type "${TYPE}" "$2"
            fi
            return
        fi
    done
}

usage()
{
    echo "Usage: set-mime [-n] [-q] directory mime.types [ mime.types ... ]"
    printf "\t-n\tDon't actually do anything, just pretend\n"
    printf "\t-q\tQuiet mode: don't display svn commands\n"
    exit 1
}

# Parse command line
while :
    do case "$1" in
        -q)
            QUIET="true"
            shift
            ;;
        -n)
            DRYRUN="true"
            shift
            ;;
        --)
            shift
            break
            ;;
        -*)
            usage
            ;;
        *)
            break
            ;;
    esac
done
case $# in
    [01])
        usage
        ;;
    *)
        DIR="$1"
        shift
        ;;
esac
i=$#
while [ "$i" -gt 0 ]; do
    MIMES="${MIMES} $1"
    shift
    i=`expr $i - 1`
done

find ${DIR} \( \! -name '.svn' -o -prune \) -a -type f -print \
  | while read FILE; do
    SUFFIX=`expr "$FILE" : "^.*\.\([^.]*\)$"`
    if [ "$SUFFIX" != "" ]; then
        for MIME in ${MIMES}; do
            scan_types $MIME $FILE $SUFFIX
        done
    fi
done

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jun 16 17:42:38 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.