[vlc-commits] update: better version comparison
Rafaël Carré
git at videolan.org
Sun Jul 17 23:43:14 CEST 2011
vlc | branch: master | Rafaël Carré <rafael.carre at gmail.com> | Sun Jul 17 17:35:17 2011 -0400| [c1a3ecd457a9d9ab720c14684a951d4a166b918b] | committer: Rafaël Carré
update: better version comparison
These days the extra vlc revision is an integer (1.1.10.1), not a
letter like in 0.8.6f days
Make PACKAGE_VERSION_* be integer, we don't need them to be strings
PACKAGE_VERSION_EXTRA now represents only this number, and is set to
0 when not used (1.1.11.0 represents 1.1.11)
Add PACKAGE_VERSION_DEV (== "git" or "rc*"), to be sure development
versions are less recent than released versions.
This string is never displayed, it is only tested for nullity
The file format on our servers can use X.Y.Z or X.Y.Z.E
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c1a3ecd457a9d9ab720c14684a951d4a166b918b
---
bin/vlc_win32_rc.rc.in | 4 +-
configure.ac | 26 ++++++--------
include/vlc_update.h | 2 +-
modules/gui/qt4/dialogs/help.cpp | 2 +-
src/libvlc_win32_rc.rc.in | 4 +-
src/misc/update.c | 73 ++++++++++++++++----------------------
6 files changed, 48 insertions(+), 63 deletions(-)
diff --git a/bin/vlc_win32_rc.rc.in b/bin/vlc_win32_rc.rc.in
index 58fc5a9..796151b 100644
--- a/bin/vlc_win32_rc.rc.in
+++ b/bin/vlc_win32_rc.rc.in
@@ -1,5 +1,5 @@
-#define VERSION_NUMBER @VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA_RC@
-#define VERSION_NUMBER_STR "@VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA_RC@"
+#define VERSION_NUMBER @VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA@
+#define VERSION_NUMBER_STR "@VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA@"
VLC_ICON ICON "vlc.ico"
diff --git a/configure.ac b/configure.ac
index bbd8162..eb7177b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,10 +3,12 @@ dnl Autoconf settings for vlc
AC_COPYRIGHT([Copyright 2002-2011 the VideoLAN team])
AC_INIT(vlc, 1.2.0-git)
-VERSION_MAJOR="1"
-VERSION_MINOR="2"
-VERSION_REVISION="0"
-VERSION_EXTRA="-git"
+VERSION_MAJOR=1
+VERSION_MINOR=2
+VERSION_REVISION=0
+VERSION_EXTRA=0
+VERSION_DEV=git
+
PKGDIR="vlc"
AC_SUBST(PKGDIR)
@@ -4262,10 +4264,11 @@ AC_DEFINE_UNQUOTED(VERSION_MESSAGE, "${VERSION_MESSAGE}", [Simple version string
AC_DEFINE_UNQUOTED(COPYRIGHT_MESSAGE, "${COPYRIGHT_MESSAGE}", [Copyright string])
AC_DEFINE_UNQUOTED(COPYRIGHT_YEARS, "${COPYRIGHT_YEARS}", [The copyright years])
AC_DEFINE_UNQUOTED(CONFIGURE_LINE, "${CONFIGURE_LINE}", [The ./configure command line])
-AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MAJOR,"${VERSION_MAJOR}", [version major number])
-AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MINOR,"${VERSION_MINOR}", [version minor number])
-AC_DEFINE_UNQUOTED(PACKAGE_VERSION_REVISION,"${VERSION_REVISION}", [version minor number])
-AC_DEFINE_UNQUOTED(PACKAGE_VERSION_EXTRA,"${VERSION_EXTRA}", [version minor number])
+AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MAJOR,${VERSION_MAJOR}, [version major number])
+AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MINOR,${VERSION_MINOR}, [version minor number])
+AC_DEFINE_UNQUOTED(PACKAGE_VERSION_REVISION,${VERSION_REVISION}, [version revision number])
+AC_DEFINE_UNQUOTED(PACKAGE_VERSION_EXTRA,${VERSION_EXTRA}, [version extra number])
+AC_DEFINE_UNQUOTED(PACKAGE_VERSION_DEV,"${VERSION_DEV}", [version development string])
AC_SUBST(COPYRIGHT_MESSAGE)
AC_SUBST(VERSION_MESSAGE)
AC_SUBST(VERSION_MAJOR)
@@ -4276,13 +4279,6 @@ AC_SUBST(COPYRIGHT_YEARS)
AC_DEFINE_UNQUOTED(VLC_COMPILE_BY, "`whoami`", [user who ran configure])
AC_DEFINE_UNQUOTED(VLC_COMPILE_HOST, "`hostname -f 2>/dev/null || hostname`", [host which ran configure])
AC_DEFINE_UNQUOTED(VLC_COMPILER, "`$CC -v 2>&1 | tail -n 1`", [compiler])
-dnl Win32 need s a numerical version_extra.
-case $( echo ${VERSION_EXTRA}|wc -m ) in
- "1") VERSION_EXTRA_RC="0";;
- "2") VERSION_EXTRA_RC=$( echo ${VERSION_EXTRA}|tr "abcdefghi" "123456789") ;;
- *) VERSION_EXTRA_RC="99"
-esac
-AC_SUBST(VERSION_EXTRA_RC)
dnl
dnl Handle substvars that use $(top_srcdir)
dnl
diff --git a/include/vlc_update.h b/include/vlc_update.h
index 5844b7c..2c56ecf 100644
--- a/include/vlc_update.h
+++ b/include/vlc_update.h
@@ -46,7 +46,7 @@ struct update_release_t
int i_major; ///< Version major
int i_minor; ///< Version minor
int i_revision; ///< Version revision
- unsigned char extra;///< Version extra
+ int i_extra; ///< Version extra
char* psz_url; ///< Download URL
char* psz_desc; ///< Release description
};
diff --git a/modules/gui/qt4/dialogs/help.cpp b/modules/gui/qt4/dialogs/help.cpp
index 1ee9000..4fee7ed 100644
--- a/modules/gui/qt4/dialogs/help.cpp
+++ b/modules/gui/qt4/dialogs/help.cpp
@@ -242,7 +242,7 @@ void UpdateDialog::updateNotify( bool b_result )
.arg( QString::number( p_release->i_major ) )
.arg( QString::number( p_release->i_minor ) )
.arg( QString::number( p_release->i_revision ) )
- .arg( ( p_release->extra )?QString( p_release->extra ):"" );
+ .arg( p_release->i_extra == 0 ? "" : "." + QString::number( p_release->i_extra ) );
ui.updateNotifyLabel->setText( message );
ui.updateNotifyTextEdit->setText( qfu( p_release->psz_desc ) );
diff --git a/src/libvlc_win32_rc.rc.in b/src/libvlc_win32_rc.rc.in
index 557c6fa..0ac9882 100644
--- a/src/libvlc_win32_rc.rc.in
+++ b/src/libvlc_win32_rc.rc.in
@@ -1,5 +1,5 @@
-#define VERSION_NUMBER @VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA_RC@
-#define VERSION_NUMBER_STR "@VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA_RC@"
+#define VERSION_NUMBER @VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA@
+#define VERSION_NUMBER_STR "@VERSION_MAJOR@, at VERSION_MINOR@, at VERSION_REVISION@, at VERSION_EXTRA@"
1 VERSIONINFO
FILETYPE 2
diff --git a/src/misc/update.c b/src/misc/update.c
index 8e15307..a3b9538 100644
--- a/src/misc/update.c
+++ b/src/misc/update.c
@@ -64,12 +64,12 @@
/*
* Here is the format of these "status files" :
- * First line is the last version: "X.Y.Ze" where:
+ * First line is the last version: "X.Y.Z.E" where:
* * X is the major number
* * Y is the minor number
* * Z is the revision number
- * * e is an OPTIONAL extra letter
- * * AKA "0.8.6d" or "0.9.0"
+ * * .E is an OPTIONAL extra number
+ * * IE "1.2.0" or "1.1.10.1"
* Second line is a url of the binary for this last version
* Remaining text is a required description of the update
*/
@@ -180,10 +180,6 @@ static void EmptyRelease( update_t *p_update )
static bool GetUpdateFile( update_t *p_update )
{
stream_t *p_stream = NULL;
- int i_major = 0;
- int i_minor = 0;
- int i_revision = 0;
- unsigned char extra;
char *psz_version_line = NULL;
char *psz_update_data = NULL;
@@ -223,18 +219,12 @@ static bool GetUpdateFile( update_t *p_update )
strncpy( psz_version_line, psz_update_data, i_len );
psz_version_line[i_len] = '\0';
- p_update->release.extra = 0;
- switch( sscanf( psz_version_line, "%i.%i.%i%c",
- &i_major, &i_minor, &i_revision, &extra ) )
+ p_update->release.i_extra = 0;
+ int ret = sscanf( psz_version_line, "%i.%i.%i.%i",
+ &p_update->release.i_major, &p_update->release.i_minor,
+ &p_update->release.i_revision, &p_update->release.i_extra);
+ if( ret != 3 && ret != 4 )
{
- case 4:
- p_update->release.extra = extra;
- case 3:
- p_update->release.i_major = i_major;
- p_update->release.i_minor = i_minor;
- p_update->release.i_revision = i_revision;
- break;
- default:
msg_Err( p_update->p_libvlc, "Update version false formated" );
goto error;
}
@@ -428,40 +418,39 @@ void* update_CheckReal( void *obj )
return NULL;
}
-/**
- * Compare a given release's version number to the current VLC's one
- *
- * \param p_update structure
- * \return true if we have to upgrade to the given version to be up to date
- */
-static bool is_strictly_greater( int * a, int * b, int n)
-{
- if( n <= 0 ) return false;
- if(a[0] > b[0] ) return true;
- if(a[0] == b[0] ) return is_strictly_greater( a+1, b+1, n-1 );
- /* a[0] < b[0] */ return false;
-}
-
bool update_NeedUpgrade( update_t *p_update )
{
assert( p_update );
- int current_version[] = {
- *PACKAGE_VERSION_MAJOR - '0',
- *PACKAGE_VERSION_MINOR - '0',
- *PACKAGE_VERSION_REVISION - '0',
- /* extra string of development versions is "-git", "-rc" ..
- * so make sure version a.b.c is newer than a.b.c-XXX */
- (*PACKAGE_VERSION_EXTRA == '-') ? -1 : *PACKAGE_VERSION_EXTRA
+ static const int current[4] = {
+ PACKAGE_VERSION_MAJOR,
+ PACKAGE_VERSION_MINOR,
+ PACKAGE_VERSION_REVISION,
+ PACKAGE_VERSION_EXTRA
};
- int latest_version[] = {
+ const int latest[4] = {
p_update->release.i_major,
p_update->release.i_minor,
p_update->release.i_revision,
- p_update->release.extra
+ p_update->release.i_extra
};
- return is_strictly_greater( latest_version, current_version, 4 );
+ for (unsigned i = 0; i < sizeof latest / sizeof *latest; i++) {
+ /* there is a new version available */
+ if (latest[i] > current[i])
+ return true;
+
+ /* current version is more recent than the latest version ?! */
+ if (latest[i] < current[i])
+ return false;
+ }
+
+ /* current version is not a release, it's a -git or -rc version */
+ if (*PACKAGE_VERSION_DEV)
+ return true;
+
+ /* current version is latest version */
+ return false;
}
/**
More information about the vlc-commits
mailing list