mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
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.
This commit is contained in:
parent
978571587a
commit
daa0326aaa
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user