COIN-OR::LEMON - Graph Library

Ticket #138: 00e953d56f15.patch

File 00e953d56f15.patch, 4.0 KB (added by Balazs Dezso, 16 years ago)
  • new file scripts/check-sources.sh

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1219507388 -7200
    # Node ID 00e953d56f15627895273a25802f798efaf47720
    # Parent  f0b89f24274560f96db7740ebb807719f5e5e369
    New code checker script and minor improvement in unifier
    
    The newly uploaded check-sources.h check the same things as
    unify-sources.h, but it does not modify the files, just checks
    the conformity. It can be used as commit checker hg hook.
    
    The way, how we enumerate the code files is changed in unify-sources.h
    because the manifest command enumerates the already removed files, which
    raise error in the script.
    
    diff -r f0b89f242745 -r 00e953d56f15 scripts/check-sources.sh
    - +  
     1#!/bin/bash
     2
     3# Add to your .hg/hgrc the following section.
     4# [hooks]
     5# pretxncommit.checksources = scripts/check-sources.sh
     6
     7YEAR=`date +2003-%Y`
     8HGROOT=`hg root`
     9
     10TAB=`echo -e '\t'`
     11
     12function check_header() {
     13    HEADER=\
     14"/* -*- mode: C++; indent-tabs-mode: nil; -*-
     15 *
     16 * This file is a part of LEMON, a generic C++ optimization library.
     17 *
     18 * Copyright (C) "$YEAR"
     19 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     20 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     21 *
     22 * Permission to use, modify and distribute this software is granted
     23 * provided that this copyright notice appears in all copies. For
     24 * precise terms see the accompanying LICENSE file.
     25 *
     26 * This software is provided \"AS IS\" with no warranty of any kind,
     27 * express or implied, and with no claim as to its suitability for any
     28 * purpose.
     29 *
     30 */"
     31
     32    HEADER_LENGTH=$(echo "$HEADER" | wc -l)
     33    FILE_HEADER=$(cat $1 | head -n $HEADER_LENGTH)
     34
     35    [[ "$FILE_HEADER" != "$HEADER" ]]
     36}
     37
     38function check_file() {
     39    echo 'check' $1 ...
     40
     41    FILE_FAILED=NO
     42    if check_header $1
     43    then
     44        echo "header failed"
     45        FILE_FAILED=YES
     46        GLOBAL_FAILED=YES
     47    fi
     48
     49    if grep -q -E "$TAB" $1
     50    then
     51        echo "tabs failed:"     
     52        grep -n -E "$TAB" $1
     53        FILE_FAILED=YES
     54        GLOBAL_FAILED=YES
     55    fi
     56
     57    if grep -q -E ' $' $1
     58    then
     59        echo "trailing spaces failed:"
     60        grep -n -E ' $' $1
     61        FILE_FAILED=YES
     62        GLOBAL_FAILED=YES
     63    fi
     64
     65    if grep -q -E '.{81,}' $1
     66    then
     67        echo "long lines failed:"
     68        grep -n -E '.{81,}' $1
     69        if [ $GLOBAL_FAILED != YES ]
     70        then
     71            echo -n "Abort commit? (yes/no) "
     72            read RESULT
     73            if [ "$RESULT" != "no" ]
     74            then
     75                FILE_FAILED=YES
     76                GLOBAL_FAILED=YES
     77            fi
     78        fi
     79    fi
     80
     81    if [[ $FILE_FAILED = YES ]];
     82    then
     83        ((FAILED_FILES++))
     84    fi
     85}
     86
     87FAILED_FILES=0
     88TOTAL_FILES=0
     89GLOBAL_FAILED=NO
     90
     91function changed_files() {
     92    {
     93        if [ -n "$HG_PARENT1" ]
     94        then
     95            hg status --rev $HG_PARENT1:$HG_NODE -a -m
     96        fi
     97        if [ -n "$HG_PARENT2" ]
     98        then
     99            hg status --rev $HG_PARENT2:$HG_NODE -a -m
     100        fi
     101    } | cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
     102}
     103
     104if [ $# == 0 ]; then
     105    echo Check all modified files...
     106
     107    while read FILENAME
     108    do
     109        check_file "$HGROOT/$FILENAME"
     110        ((TOTAL_FILES++))
     111    done < <(changed_files)
     112    echo '  done.'
     113else
     114    for i in $@
     115    do
     116        check_file $i
     117        ((TOTAL_FILES++))
     118    done
     119fi
     120
     121echo $FAILED_FILES out of $TOTAL_FILES files has failed.
     122
     123[[ $GLOBAL_FAILED == NO ]]
  • scripts/unify-sources.sh

    diff -r f0b89f242745 -r 00e953d56f15 scripts/unify-sources.sh
    a b  
    104104    fi
    105105}
    106106
     107function list_files() {
     108    hg status -a -m -c |
     109    cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
     110}
     111
    107112CHANGED_FILES=0
    108113TOTAL_FILES=0
    109114LONG_LINE_FILES=0
    110115if [ $# == 0 ]; then
    111116    echo Update all source files...
    112     for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
     117    while read i
    113118    do
    114119        update_file $HGROOT/$i
    115120        ((TOTAL_FILES++))
    116     done
     121    done < <(list_files)
    117122    echo '  done.'
    118123else
    119     for i in $*
     124    for i in $@
    120125    do
    121126        update_file $i
    122127        ((TOTAL_FILES++))