diff options
author | lulf <lulf@FreeBSD.org> | 2008-11-19 14:53:20 +0000 |
---|---|---|
committer | lulf <lulf@FreeBSD.org> | 2008-11-19 14:53:20 +0000 |
commit | 49d71b658410e80cf74bbb9e9eff44726c3ff914 (patch) | |
tree | 33c1bdefd7b26eb50095483209d7075db2875204 /contrib | |
parent | 5de5584baa3a35fc190a42dcf93491aa3fb4e2df (diff) | |
download | FreeBSD-src-49d71b658410e80cf74bbb9e9eff44726c3ff914.zip FreeBSD-src-49d71b658410e80cf74bbb9e9eff44726c3ff914.tar.gz |
- Fixup the rcs revision comparing to be correct this time.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/csup/misc.c | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/contrib/csup/misc.c b/contrib/csup/misc.c index e02bca2..ae16b59 100644 --- a/contrib/csup/misc.c +++ b/contrib/csup/misc.c @@ -578,24 +578,41 @@ bt_free(struct backoff_timer *bt) int rcsnum_cmp(char *revision1, char *revision2) { - char *ptr1, *ptr2; - - ptr1 = revision1; - ptr2 = revision2; - while (*ptr1 != '\0' && *ptr2 != '\0') { - if (*ptr1 > *ptr2) - return (1); - else if (*ptr1 < *ptr2) - return (-1); - ptr1++; - ptr2++; - }; - - if (*ptr1 != '\0' && *ptr2 == '\0') - return (1); - if (*ptr1 == '\0' && *ptr2 != '\0') - return (-1); - return (0); + char *ptr1, *ptr2, *dot1, *dot2; + int num1len, num2len, ret; + + ptr1 = revision1; + ptr2 = revision2; + while (*ptr1 != '\0' && *ptr2 != '\0') { + dot1 = strchr(ptr1, '.'); + dot2 = strchr(ptr2, '.'); + if (dot1 == NULL) + dot1 = strchr(ptr1, '\0'); + if (dot2 == NULL) + dot2 = strchr(ptr2, '\0'); + + num1len = dot1 - ptr1; + num2len = dot2 - ptr2; + /* Check the distance between each, showing how many digits */ + if (num1len > num2len) + return (1); + else if (num1len < num2len) + return (-1); + + /* Equal distance means we must check each character. */ + ret = strncmp(ptr1, ptr2, num1len); + if (ret != 0) + return (ret); + ptr1 = (*dot1 == '.') ? (dot1 + 1) : dot1; + ptr2 = (*dot2 == '.') ? (dot2 + 1) : dot2; + } + + if (*ptr1 != '\0' && *ptr2 == '\0') + return (1); + if (*ptr1 == '\0' && *ptr2 != '\0') + return (-1); + return (0); + } /* Returns 0 if a rcsrev is not a trunk revision number. */ |