From: Eric S. Raymond Date: Mon, 1 Sep 2003 19:51:01 +0000 (+0000) Subject: Fix the comparison function. X-Git-Tag: 1.0~90 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=d48fe45e935b33feda8904767ad2904ac47453e4;p=comparator.git Fix the comparison function. --- diff --git a/report.c b/report.c index 2052f90..2327c63 100644 --- a/report.c +++ b/report.c @@ -311,7 +311,18 @@ struct match_t *reduce_matches(int localdups) int sortchunk(void *a, void *b) /* sort by hash */ { - return HASHCMP((struct sorthash_t *)a, (struct sorthash_t *)b); + int cmp = HASHCMP((struct sorthash_t *)a, (struct sorthash_t *)b); + + /* + * Using the file name as a secondary key implies that, later on when + * we use sort adjacency to build a duplicates list, the duplicates + * will be ordered by filename -- thus, implicitly, by tree of origin. + */ + if (cmp) + return(cmp); + else + return(strcmp(((struct sorthash_t *)a)->file, + ((struct sorthash_t *)b)->file)); } main(int argc, char *argv[])