COIN-OR::LEMON - Graph Library

Ticket #138: e7a4f5ef2250.patch

File e7a4f5ef2250.patch, 3.9 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 1219342004 -7200
    # Node ID e7a4f5ef2250ec5edae3a5a8ab38e965dc71422d
    # Parent  81cfc04531e8fcf0a6e72f22ff2871fcb827c416
    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 81cfc04531e8 -r e7a4f5ef2250 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
     104echo "$HG_NODE"---"$HG_PARENT1"---"$HG_PARENT2"
     105if [ -n "$HG_PARENT1" ]
     106then
     107    hg status --rev $HG_PARENT1:$HG_NODE -a -m
     108fi
     109if [ -n "$HG_PARENT2" ]
     110then
     111    hg status --rev $HG_PARENT2:$HG_NODE -a -m
     112fi
     113
     114if [ $# == 0 ]; then
     115    echo Check all modified files...
     116
     117    for FILENAME in $(changed_files)
     118    do
     119        check_file "$HGROOT/$FILENAME"
     120        ((TOTAL_FILES++))
     121    done
     122    echo '  done.'
     123else
     124    for i in $*
     125    do
     126        check_file $i
     127        ((TOTAL_FILES++))
     128    done
     129fi
     130
     131echo $FAILED_FILES out of $TOTAL_FILES files has failed.
     132
     133[[ $GLOBAL_FAILED == NO ]]
     134 No newline at end of file
  • scripts/unify-sources.sh

    diff -r 81cfc04531e8 -r e7a4f5ef2250 scripts/unify-sources.sh
    a b  
    109109LONG_LINE_FILES=0
    110110if [ $# == 0 ]; then
    111111    echo Update all source files...
    112     for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
     112    for i in `hg status -m -a -c | cut -d ' ' -f 2 |grep -E  '\.(cc|h|dox)$'`
    113113    do
    114114        update_file $HGROOT/$i
    115115        ((TOTAL_FILES++))