Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r1589 - trunk: . fsvs fsvs/src fsvs/src/dox fsvs/tests

fsvs
Discussion topic

Back to topic list

svn commit: r1589 - trunk: . fsvs fsvs/src fsvs/src/dox fsvs/tests

Author pmarek
Full name P.Marek
Date 2008-04-03 22:17:59 PDT
Message Author: pmarek Date: 2008-04-03 22:17:59-0700 New Revision: 1589 Modified: trunk/ (props changed) trunk/fsvs/CHANGES trunk/fsvs/src/diff.c trunk/fsvs/src/dox/options.dox trunk/fsvs/src/options.c trunk/fsvs/src/options.h trunk/fsvs/tests/026_diff Log: Allow an arbitrary colordiff executable, with some fixes. Modified: trunk/fsvs/CHANGES Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/CHANGES?view=diff&rev=1589&p1=trunk/fsvs/CHANGES&p2=trunk/fsvs/CHANGES&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/CHANGES (original) +++ trunk/fsvs/CHANGES 2008-04-03 22:17:59-0700 @@ -6,6 +6,8 @@ line, too. (But it's not possible to override the paths from the config file.) - Fixed EPIPE handling in many functions, most notably on "fsvs st" output. +- The colordiff option has changed; it can now be used to specify the + binary to use instead of the default "colordiff". Changes since 1.1.13 - New option for conflict handling; allows "stop" (historical default), Modified: trunk/fsvs/src/diff.c Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/src/diff.c?view=diff&rev=1589&p1=trunk/fsvs/src/diff.c&p2=trunk/fsvs/src/diff.c&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/src/diff.c (original) +++ trunk/fsvs/src/diff.c 2008-04-03 22:17:59-0700 @@ -177,7 +177,7 @@ tmp_pid, WEXITSTATUS(ch_stat), ch_stat); STOPIF_CODE_ERR( !WIFEXITED(ch_stat), EIO, - "Child %d terminated abnormally", last_child); + "!Child %d terminated abnormally", tmp_pid); if (WEXITSTATUS(ch_stat) == 1) DEBUGP("exit code 1 - file has changed."); @@ -491,6 +491,32 @@ } +/** A cheap replacement for colordiff. + * Nothing more than a \c cat. */ +int df___cheap_colordiff(void) +{ + int status; + char *tmp; + const int tmp_size=16384; + + status=0; + tmp=alloca(tmp_size); + while ( (status=read(STDIN_FILENO,tmp, tmp_size)) > 0 ) + if ( (status=write(STDOUT_FILENO, tmp, status)) == -1) + break; + + if (status == -1) + { + STOPIF_CODE_ERR(errno != EPIPE, errno, + "Getting or pushing diff data"); + status=0; + } + +ex: + return status; +} + + /** Tries to start colordiff. * If colordiff can not be started, but the option says \c auto, we just * forward the data. Sadly neither \c splice nor \c sendfile are available @@ -498,14 +524,15 @@ * */ int df___colordiff(int *handle, pid_t *cd_pid) { - static const char program[]="colordiff"; + const char *program; int status; - char *tmp; - const int tmp_size=16384; int pipes[2], fdflags; - status=0; + program=opt__get_int(OPT__COLORDIFF) ? + opt__get_string(OPT__COLORDIFF) : + "colordiff"; + STOPIF_CODE_ERR( pipe(pipes) == -1, errno, "No more pipes"); @@ -524,17 +551,17 @@ execlp( program, program, NULL); - if (opt__get_int(OPT__COLORDIFF) == OPT__YES) + + /* "" as value means best effort, so no error. */ + if (opt__get_int(OPT__COLORDIFF) != 0) STOPIF_CODE_ERR(1, errno, - "Cannot start \"%s\" program", program); + "!Cannot start colordiff program \"%s\"", program); /* Well ... do the best. */ - tmp=alloca(tmp_size); - while ( (status=read(STDIN_FILENO,tmp, tmp_size)) > 0 ) - write(STDOUT_FILENO, tmp, status); - - STOPIF_CODE_ERR( status == -1, errno, "Cannot get data"); - exit(0); + /* We cannot use STOPIF() and similar, as that would return back up to + * main - and possibly cause problems somewhere else. */ + status=df___cheap_colordiff(); + exit(status ? 1 : 0); } close(pipes[0]); @@ -585,7 +612,8 @@ signal(SIGHUP, df___signal); /* check for colordiff */ - if (opt__get_int(OPT__COLORDIFF) && + if (( opt__get_int(OPT__COLORDIFF)==0 || + opt__doesnt_say_off(opt__get_string(OPT__COLORDIFF)) ) && (isatty(STDOUT_FILENO) || opt__get_prio(OPT__COLORDIFF) > PRIO_PRE_CMDLINE) ) { Modified: trunk/fsvs/src/dox/options.dox Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/src/dox/options.dox?view=diff&rev=1589&p1=trunk/fsvs/src/dox/options.dox&p2=trunk/fsvs/src/dox/options.dox&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/src/dox/options.dox (original) +++ trunk/fsvs/src/dox/options.dox 2008-04-03 22:17:59-0700 @@ -201,13 +201,14 @@ It can take on of these values: - \c no, \c off or \c false: Don't use \c colordiff. -- \c yes, \c true or \c on: If this option is set on the commandline, or - the output is a tty, pipe the output of the \c diff program (see \ref - o_diff) to \c colordiff. -- \c auto: Like yes, but don't throw an error if colordiff can't be - started; just pipe the data as-is to \c STDOUT. +- "", ie. empty (default value): Try to use \c colordiff as executable, but + don't throw an error if it can't be started; just pipe the data as-is to + \c STDOUT. +- anything else: Pipe the output of the \c diff program (see \ref o_diff) + to the given executable. -The default value is \c auto. +Please note that if \c STDOUT is not a tty (eg. is redirected into a file), +this option must be given on the command line to take effect. \section o_filter Filtering entries Modified: trunk/fsvs/src/options.c Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/src/options.c?view=diff&rev=1589&p1=trunk/fsvs/src/options.c&p2=trunk/fsvs/src/options.c&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/src/options.c (original) +++ trunk/fsvs/src/options.c 2008-04-03 22:17:59-0700 @@ -47,7 +47,9 @@ { .string=NULL, } }; -/** Strings for auto/yes/no settings. */ +/** Strings for auto/yes/no settings. + * + * Don't change the order without changing all users! */ const struct opt___val_str_t opt___yes_no_auto[]= { { .val=OPT__AUTO, .string="auto" }, { .val=OPT__YES, .string="yes" }, @@ -133,8 +135,7 @@ .parse=opt___strings2empty_bm, .parm=opt___log_output_strings, }, [OPT__COLORDIFF] = { - .name="colordiff", .i_val=OPT__AUTO, - .parse=opt___string2val, .parm=opt___yes_no_auto, + .name="colordiff", .cp_val=NULL, .parse=opt___store_string, }, [OPT__DIR_SORT] = { .name="dir_sort", .i_val=OPT__NO, @@ -228,7 +229,8 @@ /** Find an integer value by comparing with predefined strings. */ -inline int opt___find_string(const struct opt___val_str_t *list, char *string, +inline int opt___find_string(const struct opt___val_str_t *list, + const char *string, int *result) { for(; list->string; list++) @@ -556,3 +558,17 @@ else return EINVAL; } + + +/** -. + * Invalid values are handled by returning \c 1, ie. they don't say \c off. + * */ +int opt__doesnt_say_off(const char *string) +{ + int i; + + i=OPT__YES; + if (opt___find_string(opt___yes_no_auto+4, string, &i)) return 1; + return i; +} + Modified: trunk/fsvs/src/options.h Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/src/options.h?view=diff&rev=1589&p1=trunk/fsvs/src/options.h&p2=trunk/fsvs/src/options.h&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/src/options.h (original) +++ trunk/fsvs/src/options.h 2008-04-03 22:17:59-0700 @@ -223,6 +223,10 @@ * Will use hlp__vpathcopy(), with parameters swapped (\a prio first). */ int opt__load_settings(char *path, char *name, enum opt__prio_e prio); +/** Returns \c 0 if the \a string is an \b off value (like \c off, \c + * false, or \c no). */ +int opt__doesnt_say_off(const char *string); + /** \name Specific data for single options. * @{ */ Modified: trunk/fsvs/tests/026_diff Url: http://fsvs.tigris.org/source/browse/fsvs/trunk/fsvs/tests/026_diff?view=diff&rev=1589&p1=trunk/fsvs/tests/026_diff&p2=trunk/fsvs/tests/026_diff&r1=1588&r2=1589 ============================================================================== --- trunk/fsvs/tests/026_diff (original) +++ trunk/fsvs/tests/026_diff 2008-04-03 22:17:59-0700 @@ -101,6 +101,30 @@ # Try colordiff auto mode -$BINdflt diff -v $copy -o colordiff=auto > /dev/null +$BINdflt diff -v $copy -o colordiff="" > /dev/null + +# Try error handling +if $BINdflt diff $copy -o colordiff=mustneverexist_invalidbinary.$$.$RANDOM > /dev/null 2>&1 +then + $ERROR "Doesn't error out for an invalid colordiff name?" +else + $SUCCESS "Reports bad names for colordiff" +fi + +# True immediately exits +if $BINdflt diff $copy -o colordiff=true > /dev/null 2>&1 +then + $ERROR "Doesn't error out for a non-reading colordiff?" +else + $SUCCESS "Reports stopping colordiffs" +fi + +# EPIPE? +if $BINdflt diff $copy -o colordiff=cat | true +then + $SUCCESS "Ignores EPIPE" +else + $ERROR "Doesn't handle EPIPE" +fi

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r1589 - trunk: . fsvs fsvs/src fsvs/src/dox fsvs/tests pmarek P.Marek 2008-04-03 22:17:59 PDT
Messages per page: