COIN-OR::LEMON - Graph Library

Ticket #138: a8f15f9907db.patch

File a8f15f9907db.patch, 4.4 KB (added by Balazs Dezso, 13 years ago)
  • new file scripts/check-sources.sh

    # HG changeset patch
    # User "Balazs Dezso <deba@inf.elte.hu>"
    # Date 1221658957 -7200
    # Node ID a8f15f9907db4f0638fec9bab87d18e69cfae5e5
    # Parent  c691064dfd4f2e3d4e230a1fd9845a1d96de2a5d
    Several improvements in code checking and unification
    
    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.
    
    The Makefile.am files are included into the checking and unification.
    
    diff -r c691064dfd4f -r a8f15f9907db 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   
     43    if echo $1 | grep -q -v -E 'Makefile\.am$'
     44    then
     45        if check_header $1
     46        then
     47            echo "header failed"
     48            FILE_FAILED=YES
     49            GLOBAL_FAILED=YES
     50        fi
     51    fi
     52
     53    if grep -q -E "$TAB" $1
     54    then
     55        echo "tabs failed:"     
     56        grep -n -E "$TAB" $1
     57        FILE_FAILED=YES
     58        GLOBAL_FAILED=YES
     59    fi
     60
     61    if grep -q -E ' $' $1
     62    then
     63        echo "trailing spaces failed:"
     64        grep -n -E ' $' $1
     65        FILE_FAILED=YES
     66        GLOBAL_FAILED=YES
     67    fi
     68
     69    if grep -q -E '.{81,}' $1
     70    then
     71        echo "long lines failed:"
     72        grep -n -E '.{81,}' $1
     73        if [ $GLOBAL_FAILED != YES ]
     74        then
     75            echo -n "Abort commit? (yes/no) "
     76            read RESULT
     77            if [ "$RESULT" != "no" ]
     78            then
     79                FILE_FAILED=YES
     80                GLOBAL_FAILED=YES
     81            fi
     82        fi
     83    fi
     84
     85    if [[ $FILE_FAILED = YES ]];
     86    then
     87        ((FAILED_FILES++))
     88    fi
     89}
     90
     91FAILED_FILES=0
     92TOTAL_FILES=0
     93GLOBAL_FAILED=NO
     94
     95function changed_files() {
     96    {
     97        if [ -n "$HG_PARENT1" ]
     98        then
     99            hg status --rev $HG_PARENT1:$HG_NODE -a -m
     100        fi
     101        if [ -n "$HG_PARENT2" ]
     102        then
     103            hg status --rev $HG_PARENT2:$HG_NODE -a -m
     104        fi
     105    } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq
     106}
     107
     108if [ $# == 0 ]; then
     109    echo Check all modified files...
     110
     111    while read FILENAME
     112    do
     113        check_file "$HGROOT/$FILENAME"
     114        ((TOTAL_FILES++))
     115    done < <(changed_files)
     116    echo '  done.'
     117else
     118    for i in $@
     119    do
     120        check_file $i
     121        ((TOTAL_FILES++))
     122    done
     123fi
     124
     125echo $FAILED_FILES out of $TOTAL_FILES files has failed.
     126
     127[[ $GLOBAL_FAILED == NO ]]
  • scripts/unify-sources.sh

    diff -r c691064dfd4f -r a8f15f9907db scripts/unify-sources.sh
    a b  
    7272function update_file() {
    7373    echo -n '    update' $i ...
    7474
    75     update_header $1
     75    if echo $1 | grep -q -v -E 'Makefile\.am$'
     76    then
     77        update_header $1
     78    fi
    7679    update_tabs $1
    7780    remove_trailing_space $1
    7881
     
    104107    fi
    105108}
    106109
     110function list_files() {
     111    hg status -a -m -c |
     112    cut -d ' ' -f 2 | grep -E  '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq
     113}
     114
    107115CHANGED_FILES=0
    108116TOTAL_FILES=0
    109117LONG_LINE_FILES=0
    110118if [ $# == 0 ]; then
    111119    echo Update all source files...
    112     for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
     120    while read i
    113121    do
    114122        update_file $HGROOT/$i
    115123        ((TOTAL_FILES++))
    116     done
     124    done < <(list_files)
    117125    echo '  done.'
    118126else
    119     for i in $*
     127    for i in $@
    120128    do
    121129        update_file $i
    122130        ((TOTAL_FILES++))