[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r9977: Twiddle tor_version_as_new_as() so we can check for particul (in tor/trunk: . src/or)



Author: nickm
Date: 2007-04-16 20:58:30 -0400 (Mon, 16 Apr 2007)
New Revision: 9977

Modified:
   tor/trunk/
   tor/trunk/src/or/
   tor/trunk/src/or/or.h
   tor/trunk/src/or/routerparse.c
   tor/trunk/src/or/test.c
Log:
 r12418@catbus:  nickm | 2007-04-16 20:58:25 -0400
 Twiddle tor_version_as_new_as() so we can check for particular svn revisions.  With unit tests, for added freshness.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12418] on 8246c3cf-6607-4228-993b-4d95d33730f1


Property changes on: tor/trunk/src/or
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
tor
test
.deps
*.gcov
*.gcno
*.gcda

   + Makefile
Makefile.in
micro-revision.i
tor
test
.deps
*.gcov
*.gcno
*.gcda


Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-04-16 23:56:31 UTC (rev 9976)
+++ tor/trunk/src/or/or.h	2007-04-17 00:58:30 UTC (rev 9977)
@@ -3084,6 +3084,7 @@
   enum { VER_PRE=0, VER_RC=1, VER_RELEASE=2, } status;
   int patchlevel;
   char status_tag[MAX_STATUS_TAG_LEN];
+  int svn_revision;
 } tor_version_t;
 
 typedef enum version_status_t {

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-04-16 23:56:31 UTC (rev 9976)
+++ tor/trunk/src/or/routerparse.c	2007-04-17 00:58:30 UTC (rev 9977)
@@ -1947,7 +1947,7 @@
 tor_version_as_new_as(const char *platform, const char *cutoff)
 {
   tor_version_t cutoff_version, router_version;
-  char *s, *start;
+  char *s, *s2, *start;
   char tmp[128];
 
   tor_assert(platform);
@@ -1962,6 +1962,10 @@
   start = (char *)eat_whitespace(platform+3);
   if (!*start) return 0;
   s = (char *)find_whitespace(start); /* also finds '\0', which is fine */
+  s2 = (char*)eat_whitespace(s);
+  if (!strcmpstart(s2, "(r"))
+    s = (char*)find_whitespace(s2);
+
   if ((size_t)(s-start+1) >= sizeof(tmp)) /* too big, no */
     return 0;
   strlcpy(tmp, start, s-start+1);
@@ -1971,6 +1975,15 @@
     return 1; /* be safe and say yes */
   }
 
+  /* Here's why we don't need to do any special handling for svn revisions:
+   * - If neither has an svn revision, we're fine.
+   * - If the router doesn't have an svn revision, we can't assume that it
+   *   is "at least" any svn revision, so we need to return 0.
+   * - If the target version doesn't have an svn revision, any svn revision
+   *   (or none at all) is good enough, so return 1.
+   * - If both target and router have an svn revision, we compare them.
+   */
+
   return tor_version_compare(&router_version, &cutoff_version) >= 0;
 }
 
@@ -1979,7 +1992,8 @@
 int
 tor_version_parse(const char *s, tor_version_t *out)
 {
-  char *eos=NULL, *cp=NULL;
+  char *eos=NULL;
+  const char *cp=NULL;
   /* Format is:
    *   "Tor " ? NUM dot NUM dot NUM [ ( pre | rc | dot ) NUM [ - tag ] ]
    */
@@ -2033,8 +2047,20 @@
   /* Get status tag. */
   if (*cp == '-' || *cp == '.')
     ++cp;
-  strlcpy(out->status_tag, cp, sizeof(out->status_tag));
+  eos = (char*) find_whitespace(cp);
+  if (eos-cp >= (int)sizeof(out->status_tag))
+    strlcpy(out->status_tag, cp, sizeof(out->status_tag));
+  else {
+    memcpy(out->status_tag, cp, eos-cp);
+    out->status_tag[eos-cp] = 0;
+  }
+  cp = eat_whitespace(eos);
 
+  if (!strcmpstart(cp, "(r")) {
+    cp += 2;
+    out->svn_revision = strtol(cp,&eos,10);
+  }
+
   return 0;
 }
 
@@ -2056,8 +2082,10 @@
     return i;
   else if ((i = a->patchlevel - b->patchlevel))
     return i;
-
-  return strcmp(a->status_tag, b->status_tag);
+  else if ((i = strcmp(a->status_tag, b->status_tag)))
+    return i;
+  else
+    return a->svn_revision - b->svn_revision;
 }
 
 /** Return true iff versions <b>a</b> and <b>b</b> belong to the same series.

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2007-04-16 23:56:31 UTC (rev 9976)
+++ tor/trunk/src/or/test.c	2007-04-17 00:58:30 UTC (rev 9977)
@@ -1918,6 +1918,21 @@
           "Tor 0.0.8 on Darwin 64-121-192-100.c3-0."
           "sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8.2"));
 
+  /* Now try svn revisions. */
+  test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
+                                   "Tor 0.2.1.0-dev (r99)"));
+  test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100) on Banana Jr",
+                                   "Tor 0.2.1.0-dev (r99) on Hal 9000"));
+  test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
+                                   "Tor 0.2.1.0-dev on Colossus"));
+  test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99)",
+                                   "Tor 0.2.1.0-dev (r100)"));
+  test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99) on MCP",
+                                   "Tor 0.2.1.0-dev (r100) on AM"));
+  test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev",
+                                   "Tor 0.2.1.0-dev (r99)"));
+  test_eq(1, tor_version_as_new_as("Tor 0.2.1.1",
+                                   "Tor 0.2.1.0-dev (r99)"));
 }
 
 static void