summaryrefslogtreecommitdiff
path: root/src/or/routerparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-06-12 13:38:37 -0400
committerNick Mathewson <nickm@torproject.org>2009-08-21 12:31:13 -0400
commitdaa0326aaaa85a760be94ee2360cfa61a9fb5be2 (patch)
treedb6484f8eb65fd7cfc02af66f681b21f9cff41b4 /src/or/routerparse.c
parent978571587a85bebb37ec3cb9c2ea1fde1cecd6d7 (diff)
downloadtor-daa0326aaaa85a760be94ee2360cfa61a9fb5be2.tar.gz
tor-daa0326aaaa85a760be94ee2360cfa61a9fb5be2.zip
Add the first 8 bytes of the git commit digest to our versions.
Note that unlike subversion revision numbers, it isn't meaningful to compare these for anything but equality. We define a sort-order anyway, in case one of these accidentally slips into a recommended-versions list.
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r--src/or/routerparse.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index c1a7fbcfae..9736c4e000 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -3325,7 +3325,7 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
if (!*start) return 0;
s = (char *)find_whitespace(start); /* also finds '\0', which is fine */
s2 = (char*)eat_whitespace(s);
- if (!strcmpstart(s2, "(r"))
+ if (!strcmpstart(s2, "(r") || !strcmpstart(s2, "(git-"))
s = (char*)find_whitespace(s2);
if ((size_t)(s-start+1) >= sizeof(tmp)) /* too big, no */
@@ -3421,6 +3421,21 @@ tor_version_parse(const char *s, tor_version_t *out)
if (!strcmpstart(cp, "(r")) {
cp += 2;
out->svn_revision = (int) strtol(cp,&eos,10);
+ } else if (!strcmpstart(cp, "(git-")) {
+ char *close_paren = strchr(cp, ')');
+ int hexlen;
+ char digest[DIGEST_LEN];
+ if (! close_paren)
+ return -1;
+ cp += 5;
+ hexlen = (close_paren-cp);
+ memset(digest, 0, sizeof(digest));
+ if (hexlen > HEX_DIGEST_LEN || hexlen == 0 || (hexlen % 2) == 1)
+ return -1;
+ if (base16_decode(digest, hexlen/2, cp, hexlen))
+ return -1;
+ memcpy(out->git_tag, digest, hexlen/2);
+ out->git_tag_len = hexlen/2;
}
return 0;
@@ -3446,8 +3461,14 @@ tor_version_compare(tor_version_t *a, tor_version_t *b)
return i;
else if ((i = strcmp(a->status_tag, b->status_tag)))
return i;
+ else if ((i = a->svn_revision - b->svn_revision))
+ return i;
+ else if ((i = a->git_tag_len - b->git_tag_len))
+ return i;
+ else if (a->git_tag_len)
+ return memcmp(a->git_tag, b->git_tag, a->git_tag_len);
else
- return a->svn_revision - b->svn_revision;
+ return 0;
}
/** Return true iff versions <b>a</b> and <b>b</b> belong to the same series.