[asterisk-commits] git migration: Remove support for file versions (asterisk[certified/11.6])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 22 16:13:33 CDT 2015


Mark Michelson has submitted this change and it was merged.

Change subject: git migration: Remove support for file versions
......................................................................


git migration: Remove support for file versions

Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file.
As a result, this patch removes Asterisk's support for showing source file
versions.

Specifically, it does the following:
* main/asterisk:
  - Refactor the file_version structure to reflect that it no longer
    tracks a version field.
  - Alter the "core show file version" CLI command such that it always
    reports the version of Asterisk. The file version is no longer
    available.

* main/manager: The Version key now always reports the Asterisk version.

* UPGRADE: Add notes for:
  - Modification to the ModuleCheck AMI Action.
  - Modification to the CLI "core show file version" command.

Change-Id: Ia932d3c64cd18a14a3c894109baa657ec0a85d28
---
M UPGRADE.txt
M include/asterisk.h
M main/asterisk.c
M main/manager.c
4 files changed, 83 insertions(+), 58 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved; Verified



diff --git a/UPGRADE.txt b/UPGRADE.txt
index b1c63b9..f62abea 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -20,6 +20,25 @@
 ===
 ===========================================================
 
+from 11.6-cert11 to 11.6-cert12:
+
+Source Control:
+ - Asterisk has moved from Subversion to Git. As a result, several changes
+   were required in functionality. These are listed individually in the
+   notes below.
+
+AMI:
+ - The 'ModuleCheck' Action's Version key will now always report the
+   current version of Asterisk.
+
+CLI:
+ - The 'core show file version' command has been altered. In the past,
+   this command would show the SVN revision of the source files compiled
+   in Asterisk. However, when Asterisk moved to Git, the source control
+   version support was removed. As a result, the version information shown
+   by the CLI command is always the Asterisk version. This CLI command
+   will be removed in Asterisk 14.
+
 from 11.6-cert6 to 11.6-cert7:
 
 * Due to the POODLE vulnerability (see 
diff --git a/include/asterisk.h b/include/asterisk.h
index 24e4c05..8fcf3d5 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -102,6 +102,8 @@
  * \param version the version string (typically a SVN revision keyword string)
  * \return nothing
  *
+ * \note As of 11.18.0, the \c version parameter is ignored.
+ *
  * This function should not be called directly, but instead the
  * ASTERISK_FILE_VERSION macro should be used to register a file with the core.
  */
@@ -118,12 +120,29 @@
  */
 void ast_unregister_file_version(const char *file);
 
-/*! \brief Find version for given module name
+/*!
+ * \brief Find version for given module name
  * \param file Module name (i.e. chan_sip.so)
- * \return version string or NULL if the module is not found
+ *
+ * \note As of 11.18.0, the file version is no longer tracked. As such,
+ * if the file exists, the Asterisk version will be returned.
+ *
+ * \retval NULL if the file doesn't exist.
+ * \retval The Asterisk version if the file does exist.
  */
 const char *ast_file_version_find(const char *file);
 
+/*!
+ * \brief Complete a source file name
+ * \param partial The partial name of the file to look up.
+ * \param n The n-th match to return.
+ *
+ * \retval NULL if there is no match for partial at the n-th position
+ * \retval Matching source file name
+ *
+ * \note A matching source file is allocataed on the heap, and must be
+ * free'd by the caller.
+ */
 char *ast_complete_source_filename(const char *partial, int n);
 
 /*!
diff --git a/main/asterisk.c b/main/asterisk.c
index eac6b8c..66cc484 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -327,88 +327,83 @@
 } sig_flags;
 
 #if !defined(LOW_MEMORY)
-struct file_version {
-	AST_RWLIST_ENTRY(file_version) list;
+struct registered_file {
+	AST_RWLIST_ENTRY(registered_file) list;
 	const char *file;
-	char *version;
 };
 
-static AST_RWLIST_HEAD_STATIC(file_versions, file_version);
+static AST_RWLIST_HEAD_STATIC(registered_files, registered_file);
 
 void ast_register_file_version(const char *file, const char *version)
 {
-	struct file_version *new;
-	char *work;
-	size_t version_length;
+	struct registered_file *reg;
 
-	work = ast_strdupa(version);
-	work = ast_strip(ast_strip_quoted(work, "$", "$"));
-	version_length = strlen(work) + 1;
-
-	if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
+	reg = ast_calloc(1, sizeof(*reg));
+	if (!reg) {
 		return;
+	}
 
-	new->file = file;
-	new->version = (char *) new + sizeof(*new);
-	memcpy(new->version, work, version_length);
-	AST_RWLIST_WRLOCK(&file_versions);
-	AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
-	AST_RWLIST_UNLOCK(&file_versions);
+	reg->file = file;
+	AST_RWLIST_WRLOCK(&registered_files);
+	AST_RWLIST_INSERT_HEAD(&registered_files, reg, list);
+	AST_RWLIST_UNLOCK(&registered_files);
 }
 
 void ast_unregister_file_version(const char *file)
 {
-	struct file_version *find;
+	struct registered_file *find;
 
-	AST_RWLIST_WRLOCK(&file_versions);
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
+	AST_RWLIST_WRLOCK(&registered_files);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&registered_files, find, list) {
 		if (!strcasecmp(find->file, file)) {
 			AST_RWLIST_REMOVE_CURRENT(list);
 			break;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
-	AST_RWLIST_UNLOCK(&file_versions);
+	AST_RWLIST_UNLOCK(&registered_files);
 
-	if (find)
+	if (find) {
 		ast_free(find);
+	}
 }
 
 char *ast_complete_source_filename(const char *partial, int n)
 {
-	struct file_version *find;
+	struct registered_file *find;
 	size_t len = strlen(partial);
 	int count = 0;
 	char *res = NULL;
 
-	AST_RWLIST_RDLOCK(&file_versions);
-	AST_RWLIST_TRAVERSE(&file_versions, find, list) {
+	AST_RWLIST_RDLOCK(&registered_files);
+	AST_RWLIST_TRAVERSE(&registered_files, find, list) {
 		if (!strncasecmp(find->file, partial, len) && ++count > n) {
 			res = ast_strdup(find->file);
 			break;
 		}
 	}
-	AST_RWLIST_UNLOCK(&file_versions);
+	AST_RWLIST_UNLOCK(&registered_files);
 	return res;
 }
 
-/*! \brief Find version for given module name */
 const char *ast_file_version_find(const char *file)
 {
-	struct file_version *iterator;
+	struct registered_file *iterator;
 
-	AST_RWLIST_WRLOCK(&file_versions);
-	AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
-		if (!strcasecmp(iterator->file, file))
+	AST_RWLIST_RDLOCK(&registered_files);
+	AST_RWLIST_TRAVERSE(&registered_files, iterator, list) {
+		if (!strcasecmp(iterator->file, file)) {
 			break;
+		}
 	}
-	AST_RWLIST_UNLOCK(&file_versions);
-	if (iterator)
-		return iterator->version;
+	AST_RWLIST_UNLOCK(&registered_files);
+
+	if (iterator) {
+		return ast_get_version();
+	}
+
 	return NULL;
 }
-
-
 
 struct thread_list_t {
 	AST_RWLIST_ENTRY(thread_list_t) list;
@@ -890,35 +885,35 @@
 static char *handle_show_version_files(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #define FORMAT "%-25.25s %-40.40s\n"
-	struct file_version *iterator;
+	struct registered_file *iterator;
 	regex_t regexbuf;
 	int havepattern = 0;
 	int havename = 0;
 	int count_files = 0;
 	char *ret = NULL;
 	int matchlen, which = 0;
-	struct file_version *find;
+	struct registered_file *find;
 
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "core show file version [like]";
 		e->usage =
 			"Usage: core show file version [like <pattern>]\n"
-			"       Lists the revision numbers of the files used to build this copy of Asterisk.\n"
+			"       Lists the files along with the Asterisk version.\n"
 			"       Optional regular expression pattern is used to filter the file list.\n";
 		return NULL;
 	case CLI_GENERATE:
 		matchlen = strlen(a->word);
 		if (a->pos != 3)
 			return NULL;
-		AST_RWLIST_RDLOCK(&file_versions);
-		AST_RWLIST_TRAVERSE(&file_versions, find, list) {
+		AST_RWLIST_RDLOCK(&registered_files);
+		AST_RWLIST_TRAVERSE(&registered_files, find, list) {
 			if (!strncasecmp(a->word, find->file, matchlen) && ++which > a->n) {
 				ret = ast_strdup(find->file);
 				break;
 			}
 		}
-		AST_RWLIST_UNLOCK(&file_versions);
+		AST_RWLIST_UNLOCK(&registered_files);
 		return ret;
 	}
 
@@ -943,20 +938,20 @@
 
 	ast_cli(a->fd, FORMAT, "File", "Revision");
 	ast_cli(a->fd, FORMAT, "----", "--------");
-	AST_RWLIST_RDLOCK(&file_versions);
-	AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
+	AST_RWLIST_RDLOCK(&registered_files);
+	AST_RWLIST_TRAVERSE(&registered_files, iterator, list) {
 		if (havename && strcasecmp(iterator->file, a->argv[4]))
 			continue;
 
 		if (havepattern && regexec(&regexbuf, iterator->file, 0, NULL, 0))
 			continue;
 
-		ast_cli(a->fd, FORMAT, iterator->file, iterator->version);
+		ast_cli(a->fd, FORMAT, iterator->file, ast_get_version());
 		count_files++;
 		if (havename)
 			break;
 	}
-	AST_RWLIST_UNLOCK(&file_versions);
+	AST_RWLIST_UNLOCK(&registered_files);
 	if (!havename) {
 		ast_cli(a->fd, "%d files listed.\n", count_files);
 	}
diff --git a/main/manager.c b/main/manager.c
index 51a3b42..23f1595 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -5083,9 +5083,6 @@
 	const char *module = astman_get_header(m, "Module");
 	const char *id = astman_get_header(m, "ActionID");
 	char idText[256];
-#if !defined(LOW_MEMORY)
-	const char *version;
-#endif
 	char filename[PATH_MAX];
 	char *cut;
 
@@ -5102,11 +5099,6 @@
 		astman_send_error(s, m, "Module not loaded");
 		return 0;
 	}
-	snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".c");
-	ast_debug(1, "**** ModuleCheck .c file %s\n", filename);
-#if !defined(LOW_MEMORY)
-	version = ast_file_version_find(filename);
-#endif
 
 	if (!ast_strlen_zero(id)) {
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
@@ -5115,7 +5107,7 @@
 	}
 	astman_append(s, "Response: Success\r\n%s", idText);
 #if !defined(LOW_MEMORY)
-	astman_append(s, "Version: %s\r\n\r\n", version ? version : "");
+	astman_append(s, "Version: %s\r\n\r\n", ast_get_version());
 #endif
 	return 0;
 }

-- 
To view, visit https://gerrit.asterisk.org/208
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia932d3c64cd18a14a3c894109baa657ec0a85d28
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/11.6
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list