]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add the first 8 bytes of the git commit digest to our versions.
authorNick Mathewson <nickm@torproject.org>
Fri, 12 Jun 2009 17:38:37 +0000 (13:38 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 21 Aug 2009 16:31:13 +0000 (12:31 -0400)
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.

ChangeLog
src/or/Makefile.am
src/or/config.c
src/or/or.h
src/or/router.c
src/or/routerparse.c
src/or/test.c
src/or/tor_main.c

index 9e6852827362d1e2b3f0babfa74ffba8f460877d..2428bed99616ab11842ec701e62aee6942167f50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -38,6 +38,8 @@ Changes in version 0.2.2.1-alpha - 2009-0?-??
       setting FetchDirInfoEarly to 1. Previous behavior will stay the same
       as only certain clients who must have this information sooner should
       set this option.
+    - Instead of adding the svn revision to the Tor version string, report
+      the git commit (when we're building from a git checkout).
 
   o Minor bugfixes:
     - If any the v3 certs we download are unparseable, we should actually
index c967a8846f55cb600b243ba6bfc376159434c928..7d6c9eb0b9e8f7b0717d57506260b9f886e3efdd 100644 (file)
@@ -57,52 +57,18 @@ config_codedigest.o: or_sha1.i
 tor_main.o: micro-revision.i
 
 micro-revision.i: FORCE
-       @svkdir=$$SVKROOT;                                      \
-       if test "x$$svkdir" = x ; then                          \
-         svkdir=$$HOME/.svk;                                   \
-       fi;                                                     \
-       if test -d ../../.git && test -x "`which git 2>&1;true`" ; then \
-         if test -d ../../.git/svn && test -x "`which git-svn 2>&1;true`" ; then \
-           git-svn info ../../README |                         \
-           sed -n 's/^Revision: \([0-9][0-9]*\).*/"\1"/p'      \
-                                          > micro-revision.tmp \
-               || true;                                        \
-         fi;                                                   \
-       elif test -d ../../.svn && test -x "`which svn 2>&1;true`" ; then \
-         svn info ../.. |                                      \
-         sed -n 's/^Revision: \([0-9][0-9]*\).*/"\1"/p' > micro-revision.tmp \
-            || true;                                           \
-       elif test -x "`which svk 2>&1;true`" && test -d $$svkdir/local; then \
-         location=../..;                                       \
-         rev=x;                                                \
-         while test x$$rev = xx; do                            \
-           x=`svk info $$location |                            \
-             sed -n 's/^Mirrored From:.*, Rev\. \([0-9][0-9]*\)/\1/p'`; \
-           if test x$$x != x; then                             \
-             rev=$$x;                                          \
-             break;                                            \
-           else                                                \
-             loc=`svk info $$location |                        \
-               sed -n 's/^Copied From: \(.*\), Rev\. [0-9][0-9]*/\1/p' | \
-               head -1`;                                       \
-             if test x$$loc = x; then                          \
-               break;                                          \
-             else                                              \
-               location=/$$loc;                                \
-             fi;                                               \
-           fi;                                                 \
-         done;                                                 \
-         if test x$$rev != xx; then                            \
-           echo \"$$rev\" > micro-revision.tmp;                \
-         fi;                                                   \
-       fi;                                                     \
-       if test ! -f micro-revision.tmp ; then                  \
-         if test ! -f micro-revision.i ; then                  \
-           echo '""' > micro-revision.i;                       \
-         fi;                                                   \
-       elif test ! -f micro-revision.i ||                      \
+       @rm -f micro-revision.tmp;                                      \
+       if test -d ../../.git && test -x "`which git 2>&1;true`"; then  \
+         HASH="`git rev-parse --short=16 HEAD`";                       \
+         echo \"$$HASH\" > micro-revision.tmp;                         \
+        fi;                                                            \
+       if test ! -f micro-revision.tmp ; then                          \
+         if test ! -f micro-revision.i ; then                          \
+           echo '""' > micro-revision.i;                               \
+         fi;                                                           \
+       elif test ! -f micro-revision.i ||                              \
          test x"`cat micro-revision.tmp`" != x"`cat micro-revision.i`"; then \
-         mv micro-revision.tmp micro-revision.i;               \
+         mv micro-revision.tmp micro-revision.i;                       \
        fi; true
 
 or_sha1.i: $(tor_SOURCES) test_data.c test.c
index de6bfcf68062d1cc1ff4073d3df66c79f581e6a9..43f88e537e4591cef2d61ebd6c6f8a78fd442d2e 100644 (file)
@@ -817,7 +817,7 @@ set_options(or_options_t *new_val, char **msg)
   return 0;
 }
 
-extern const char tor_svn_revision[]; /* from tor_main.c */
+extern const char tor_git_revision[]; /* from tor_main.c */
 
 /** The version of this Tor process, as parsed. */
 static char *_version = NULL;
@@ -827,10 +827,10 @@ const char *
 get_version(void)
 {
   if (_version == NULL) {
-    if (strlen(tor_svn_revision)) {
-      size_t len = strlen(VERSION)+strlen(tor_svn_revision)+8;
+    if (strlen(tor_git_revision)) {
+      size_t len = strlen(VERSION)+strlen(tor_git_revision)+16;
       _version = tor_malloc(len);
-      tor_snprintf(_version, len, "%s (r%s)", VERSION, tor_svn_revision);
+      tor_snprintf(_version, len, "%s (git-%s)", VERSION, tor_git_revision);
     } else {
       _version = tor_strdup(VERSION);
     }
index 7ece877504b3f17bb940d647912f7a584071b662..4d808fc3e3caaa74e18300a6dc7057fc9cdcabec 100644 (file)
@@ -4698,6 +4698,9 @@ typedef struct tor_version_t {
   int patchlevel;
   char status_tag[MAX_STATUS_TAG_LEN];
   int svn_revision;
+
+  int git_tag_len;
+  char git_tag[DIGEST_LEN];
 } tor_version_t;
 
 int router_get_router_hash(const char *s, char *digest);
index d5a25768427fcf19f94ccdeac10e8b29b0bca29e..f2747f51417b6c67d157d2c8d2a7d10e9f8072f1 100644 (file)
@@ -1608,8 +1608,6 @@ router_guess_address_from_dir_headers(uint32_t *guess)
   return -1;
 }
 
-extern const char tor_svn_revision[]; /* from tor_main.c */
-
 /** Set <b>platform</b> (max length <b>len</b>) to a NUL-terminated short
  * string describing the version of Tor and the operating system we're
  * currently running on.
index c1a7fbcfae4f5a8078f7e89de93440d03005cc48..9736c4e00010fa7ce9ff384a9dfa498b6dc4d48f 100644 (file)
@@ -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.
index db4b6784f44a8a7d27281525fe5494dd92727041..0f121a84bb4b50f74e64fccb1e66159295d54bcf 100644 (file)
@@ -5,7 +5,7 @@
 
 /* Ordinarily defined in tor_main.c; this bit is just here to provide one
  * since we're not linking to tor_main.c */
-const char tor_svn_revision[] = "";
+const char tor_git_revision[] = "";
 
 /**
  * \file test.c
@@ -3212,6 +3212,19 @@ test_dir_format(void)
                                    "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)"));
+
+  /* Now try git revisions */
+  test_eq(0, tor_version_parse("0.5.6.7 (git-ff00ff)", &ver1));
+  test_eq(0, ver1.major);
+  test_eq(5, ver1.minor);
+  test_eq(6, ver1.micro);
+  test_eq(7, ver1.patchlevel);
+  test_eq(3, ver1.git_tag_len);
+  test_memeq(ver1.git_tag, "\xff\x00\xff", 3);
+  test_eq(-1, tor_version_parse("0.5.6.7 (git-ff00xx)", &ver1));
+  test_eq(-1, tor_version_parse("0.5.6.7 (git-ff00fff)", &ver1));
+  test_eq(0, tor_version_parse("0.5.6.7 (git ff00fff)", &ver1));
+
  done:
   if (r1)
     routerinfo_free(r1);
index 137da02c412f13d02126905eee4a839e90a6347c..4a6be7cddd8fde801fec644069d3b7a98ca6f2bb 100644 (file)
@@ -7,7 +7,7 @@
  * built from.  This string is generated by a bit of shell kludging int
  * src/or/Makefile.am, and is usually right.
  */
-const char tor_svn_revision[] =
+const char tor_git_revision[] =
 #ifndef _MSC_VER
 #include "micro-revision.i"
 #endif