Try to make some semblence of sense from git revisions/tags.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5903 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2021-06-21 13:46:13 +00:00
parent b34618507a
commit a12c453c30
5 changed files with 81 additions and 27 deletions

View File

@ -1860,6 +1860,7 @@ static package_t *PM_MarkedPackage(const char *packagename, int markflag)
static void PM_RevertChanges(void) static void PM_RevertChanges(void)
{ {
package_t *p; package_t *p;
int us = parse_revision_number(enginerevision, true), them;
if (pkg_updating) if (pkg_updating)
return; return;
@ -1868,7 +1869,8 @@ static void PM_RevertChanges(void)
{ {
if (p->flags & DPF_ENGINE) if (p->flags & DPF_ENGINE)
{ {
if (!(p->flags & DPF_HIDDEN) && !strcmp(enginerevision, p->version) && (p->flags & DPF_PRESENT)) them = parse_revision_number(p->version, true);
if (!(p->flags & DPF_HIDDEN) && us && us==them && (p->flags & DPF_PRESENT))
p->flags |= DPF_AUTOMARKED; p->flags |= DPF_AUTOMARKED;
else else
p->flags &= ~DPF_MARKED; p->flags &= ~DPF_MARKED;
@ -2102,6 +2104,8 @@ unsigned int PM_MarkUpdates (void)
{ {
unsigned int changecount = 0; unsigned int changecount = 0;
package_t *p, *o, *b, *e = NULL; package_t *p, *o, *b, *e = NULL;
int bestengine = parse_revision_number(enginerevision, true);
int them;
if (manifestpackages) if (manifestpackages)
{ {
@ -2130,12 +2134,15 @@ unsigned int PM_MarkUpdates (void)
for (p = availablepackages; p; p = p->next) for (p = availablepackages; p; p = p->next)
{ {
if ((p->flags & DPF_ENGINE) && !(p->flags & DPF_HIDDEN)) if ((p->flags & DPF_ENGINE) && !(p->flags & DPF_HIDDEN) && bestengine>0 && PM_SignatureOkay(p))
{ {
them = parse_revision_number(p->version, true);
if (!(p->flags & DPF_TESTING) || pkg_autoupdate.ival >= UPD_TESTING) if (!(p->flags & DPF_TESTING) || pkg_autoupdate.ival >= UPD_TESTING)
if (!e || strcmp(e->version, p->version) < 0) //package must be more recent than the previously found engine if (them > bestengine)
if (strcmp(enginerevision, "-") && strcmp(enginerevision, p->version) < 0) //package must be more recent than the current engine too, there's no point auto-updating to an older revision. {
e = p; e = p;
bestengine = them;
}
} }
if (p->flags & DPF_MARKED) if (p->flags & DPF_MARKED)
{ {
@ -4258,6 +4265,11 @@ qboolean PM_FindUpdatedEngine(char *syspath, size_t syspathsize)
struct packagedep_s *dep; struct packagedep_s *dep;
package_t *e = NULL, *p; package_t *e = NULL, *p;
char *pfname; char *pfname;
int best = parse_revision_number(enginerevision, true);
int them;
if (best <= 0)
return false; //no idea what revision we are, we might be more recent.
//figure out what we've previously installed. //figure out what we've previously installed.
PM_PreparePackageList(); PM_PreparePackageList();
@ -4265,8 +4277,8 @@ qboolean PM_FindUpdatedEngine(char *syspath, size_t syspathsize)
{ {
if ((p->flags & DPF_ENGINE) && !(p->flags & DPF_HIDDEN) && p->fsroot == FS_ROOT) if ((p->flags & DPF_ENGINE) && !(p->flags & DPF_HIDDEN) && p->fsroot == FS_ROOT)
{ {
if ((p->flags & DPF_ENABLED) && (!e || strcmp(e->version, p->version) < 0)) them = parse_revision_number(p->version, true);
if (strcmp(enginerevision, "-") && strcmp(enginerevision, p->version) < 0) //package must be more recent than the current engine too, there's no point auto-updating to an older revision. if ((p->flags & DPF_ENABLED) && them>best)
{ {
for (dep = p->deps, pfname = NULL; dep; dep = dep->next) for (dep = p->deps, pfname = NULL; dep; dep = dep->next)
{ {
@ -4283,7 +4295,10 @@ qboolean PM_FindUpdatedEngine(char *syspath, size_t syspathsize)
if (pfname && PM_CheckFile(pfname, p->fsroot)) if (pfname && PM_CheckFile(pfname, p->fsroot))
{ {
if (FS_NativePath(pfname, p->fsroot, syspath, syspathsize)) if (FS_NativePath(pfname, p->fsroot, syspath, syspathsize))
{
e = p; e = p;
best = them;
}
} }
} }
} }

View File

@ -3005,14 +3005,7 @@ qboolean Sys_EngineMayUpdate(void)
if (!COM_CheckParm("-allowupdate")) if (!COM_CheckParm("-allowupdate"))
{ {
//no revision info in this build, meaning its custom built and thus cannot check against the available updated versions. if (revision_number(true) <= 0)
if (!strcmp(SVNREVISIONSTR, "-"))
return false;
//svn revision didn't parse as an exact number. this implies it has an 'M' in it to mark it as modified.
//either way, its bad and autoupdates when we don't know what we're updating from is a bad idea.
strtoul(SVNREVISIONSTR, &e, 10);
if (!*SVNREVISIONSTR || *e)
return false; return false;
} }

View File

@ -8112,6 +8112,60 @@ char *version_string(void)
return s; return s;
} }
//returns <=0 on error.
//this function is useful for auto updates.
int parse_revision_number(const char *s, qboolean strict)
{
int rev;
char *e;
//no revision info in this build, meaning its custom built and thus cannot check against the available updated versions.
if (!s || !strcmp(s, "-") || !*s)
return false; //no version info at all.
if (!strncmp(s, "git-", 4))
{ //git gets messy and takes the form of one of the following...
//bad: git-XXXXXXXX[-dirty]
//git-tag-extracommits-hash[-dirty]
//if 'tag' is [R]VVVV then someone's tagging revisions to match svn revisions.
//if a fork wants to block updates, then they can either just disable engine updates or they can fiddle with this tagging stuff.
s+=4;
if (*s == 'r' || *s == 'R')
s++; //R prefix is optional.
if (strict && strstr(s, "-dirty"))
return false; //boo hiss.
rev = strtoul(s, &e, 10);
if (*e == '-')
{ //we used --long so this should be a count of extra commits
if (strtoul(e+1, &e, 10) && strict)
return false; //doesn't exactly match the tag, and we're strict
if (*e != '-')
return false; //no hash info? something odd is happening...
//hash is uninteresting.
}
else //looks like there's no tag info there, just a commit hash. don't consider it a valid revision number.
return false; //--long didn't
}
else
{
//[lower-]upper[M]
rev = strtoul(s, &e, 10);
if (*e && strict)
return false; //something odd.
}
return rev;
}
int revision_number(qboolean strict)
{
#ifdef SVNREVISION
return parse_revision_number(STRINGIFY(SVNREVISION), strict);
#else
return 0;
#endif
}
//C90 //C90
void COM_TimeOfDay(date_t *date) void COM_TimeOfDay(date_t *date)
{ {

View File

@ -939,6 +939,8 @@ unsigned int CalcHashInt(const hashfunc_t *hash, const unsigned char *data, size
size_t CalcHash(const hashfunc_t *hash, unsigned char *digest, size_t maxdigestsize, const unsigned char *data, size_t datasize); size_t CalcHash(const hashfunc_t *hash, unsigned char *digest, size_t maxdigestsize, const unsigned char *data, size_t datasize);
size_t CalcHMAC(const hashfunc_t *hashfunc, unsigned char *digest, size_t maxdigestsize, const unsigned char *data, size_t datalen, const unsigned char *key, size_t keylen); size_t CalcHMAC(const hashfunc_t *hashfunc, unsigned char *digest, size_t maxdigestsize, const unsigned char *data, size_t datalen, const unsigned char *key, size_t keylen);
int parse_revision_number(const char *revstr, qboolean strict); //returns our 'svn' revision numbers
int revision_number(qboolean strict); //returns our 'svn' revision numbers
int version_number(void); int version_number(void);
char *version_string(void); char *version_string(void);

View File

@ -578,23 +578,13 @@ qboolean Sys_SetUpdatedBinary(const char *newbinary)
qboolean Sys_EngineMayUpdate(void) qboolean Sys_EngineMayUpdate(void)
{ {
char enginebinary[MAX_OSPATH]; char enginebinary[MAX_OSPATH];
char *e;
int len; int len;
#define SVNREVISIONSTR STRINGIFY(SVNREVISION) //if we can't get a revision number from our cflags then don't allow updates (unless forced on).
if (!COM_CheckParm("-allowupdate")) if (!COM_CheckParm("-allowupdate"))
{ if (revision_number(true)<=0)
//no revision info in this build, meaning its custom built and thus cannot check against the available updated versions.
if (!strcmp(SVNREVISIONSTR, "-"))
return false; return false;
//svn revision didn't parse as an exact number. this implies it has an 'M' in it to mark it as modified.
//either way, its bad and autoupdates when we don't know what we're updating from is a bad idea.
strtoul(SVNREVISIONSTR, &e, 10);
if (!*SVNREVISIONSTR || *e)
return false;
}
//update blocked via commandline //update blocked via commandline
if (COM_CheckParm("-noupdate") || COM_CheckParm("--noupdate") || COM_CheckParm("-noautoupdate") || COM_CheckParm("--noautoupdate")) if (COM_CheckParm("-noupdate") || COM_CheckParm("--noupdate") || COM_CheckParm("-noautoupdate") || COM_CheckParm("--noautoupdate"))
return false; return false;