diff options
author | Matt Jordan <mjordan@digium.com> | 2015-04-11 21:38:22 -0500 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2015-04-13 03:48:57 -0400 |
commit | 4a58261694f1538a419dd869f87ea4590171a9f2 (patch) | |
tree | a8d3196d5b69f233f814ef3fa7a543c2ce50bd24 /main/asterisk.c | |
parent | 1174ef588dafe864fe3f2c1f8297690def8f85d1 (diff) |
git migration: Refactor the ASTERISK_FILE_VERSION macro
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:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
Diffstat (limited to 'main/asterisk.c')
-rw-r--r-- | main/asterisk.c | 153 |
1 files changed, 24 insertions, 129 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index baf5ded4f..574451c65 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -149,7 +149,7 @@ #include "asterisk.h" -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") +ASTERISK_REGISTER_FILE() #include "asterisk/_private.h" @@ -475,87 +475,65 @@ static struct { } 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) +void __ast_register_file(const char *file) { - struct file_version *new; - char *work; - size_t version_length; - - work = ast_strdupa(version); - work = ast_strip(ast_strip_quoted(work, "$", "$")); - version_length = strlen(work) + 1; + struct registered_file *reg; - 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(®istered_files); + AST_RWLIST_INSERT_HEAD(®istered_files, reg, list); + AST_RWLIST_UNLOCK(®istered_files); } -void ast_unregister_file_version(const char *file) +void __ast_unregister_file(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(®istered_files); + AST_RWLIST_TRAVERSE_SAFE_BEGIN(®istered_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(®istered_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(®istered_files); + AST_RWLIST_TRAVERSE(®istered_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(®istered_files); return res; } -/*! \brief Find version for given module name */ -const char *ast_file_version_find(const char *file) -{ - struct file_version *iterator; - - AST_RWLIST_WRLOCK(&file_versions); - AST_RWLIST_TRAVERSE(&file_versions, iterator, list) { - if (!strcasecmp(iterator->file, file)) - break; - } - AST_RWLIST_UNLOCK(&file_versions); - if (iterator) - return iterator->version; - return NULL; -} - struct thread_list_t { AST_RWLIST_ENTRY(thread_list_t) list; char *name; @@ -1031,88 +1009,6 @@ static char *handle_clear_profile(struct ast_cli_entry *e, int cmd, struct ast_c } #undef DEFINE_PROFILE_MIN_MAX_VALUES -/*! \brief CLI command to list module versions */ -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; - regex_t regexbuf; - int havepattern = 0; - int havename = 0; - int count_files = 0; - char *ret = NULL; - int matchlen, which = 0; - struct file_version *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" - " 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) { - if (!strncasecmp(a->word, find->file, matchlen) && ++which > a->n) { - ret = ast_strdup(find->file); - break; - } - } - AST_RWLIST_UNLOCK(&file_versions); - return ret; - } - - - switch (a->argc) { - case 6: - if (!strcasecmp(a->argv[4], "like")) { - if (regcomp(®exbuf, a->argv[5], REG_EXTENDED | REG_NOSUB)) - return CLI_SHOWUSAGE; - havepattern = 1; - } else - return CLI_SHOWUSAGE; - break; - case 5: - havename = 1; - break; - case 4: - break; - default: - return CLI_SHOWUSAGE; - } - - ast_cli(a->fd, FORMAT, "File", "Revision"); - ast_cli(a->fd, FORMAT, "----", "--------"); - AST_RWLIST_RDLOCK(&file_versions); - AST_RWLIST_TRAVERSE(&file_versions, iterator, list) { - if (havename && strcasecmp(iterator->file, a->argv[4])) - continue; - - if (havepattern && regexec(®exbuf, iterator->file, 0, NULL, 0)) - continue; - - ast_cli(a->fd, FORMAT, iterator->file, iterator->version); - count_files++; - if (havename) - break; - } - AST_RWLIST_UNLOCK(&file_versions); - if (!havename) { - ast_cli(a->fd, "%d files listed.\n", count_files); - } - - if (havepattern) - regfree(®exbuf); - - return CLI_SUCCESS; -#undef FORMAT -} - #endif /* ! LOW_MEMORY */ static void publish_fully_booted(void) @@ -2701,7 +2597,6 @@ static struct ast_cli_entry cli_asterisk[] = { AST_CLI_DEFINE(handle_version, "Display version info"), AST_CLI_DEFINE(handle_bang, "Execute a shell command"), #if !defined(LOW_MEMORY) - AST_CLI_DEFINE(handle_show_version_files, "List versions of files used to build Asterisk"), AST_CLI_DEFINE(handle_show_threads, "Show running threads"), #if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL) AST_CLI_DEFINE(handle_show_sysinfo, "Show System Information"), |