You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2012/09/04 13:23:00 UTC

svn commit: r1380559 - in /subversion/trunk/subversion/libsvn_subr: deprecated.c opt.c opt.h sysinfo.c sysinfo.h

Author: brane
Date: Tue Sep  4 11:22:59 2012
New Revision: 1380559

URL: http://svn.apache.org/viewvc?rev=1380559&view=rev
Log:
Followup to r1379689: gather version and system information in a structure
instead of a huge string, and make combining it to stdout a separate step.

* subversion/libsvn_subr/sysinfo.h: Inclulde apr_tables.h.
  (svn_sysinfo__linked_lib_t): New struct type.
  (svn_sysinfo__linked_libs): Return an APR array of svn_sysinfo__linked_lib_t
   instead of a preconstructed string.
  (svn_sysinfo__loaded_lib_t): New struct type.
  (svn_sysinfo__loaded_libs): Return an APR array of svn_sysinfo__loaded_lib_t
   instead of a preconstructed string.

* subversion/libsvn_subr/sysinfo.c (svn_sysinfo__linked_libs): Update.
  (svn_sysinfo__loaded_libs): Update.
  (win32_shared_libs): Update, make return value an APR array.
  (release_name_from_uname) Define only unless SVN_HAVE_MACOS_PLIST
   to avoid compiler warnings about unused static function on Mac OS X.

* subversion/libsvn_subr/opt.h: Include apr_tables.h.
  (svn_opt__version_info_t): New struct. Contains all the information that
   was formerly returned in a string by svn_opt__get_version_info.
  (svn_opt__get_version_info): Change signature; returns a svn_opt__version_info_t.
  (svn_opt__print_version_info): Reinstate, but using the outpot from
   svn_opt__get_version_info.

* subversion/libsvn_subr/opt.c (svn_opt__get_version_info): Reimplement.
  (svn_opt__print_version_info): Reinstate.
  (svn_opt_print_help4): Use svn_opt__print_version_info again.
* subversion/libsvn_subr/deprecated.c
  (svn_opt_print_help): Use svn_opt__print_version_info again.

Modified:
    subversion/trunk/subversion/libsvn_subr/deprecated.c
    subversion/trunk/subversion/libsvn_subr/opt.c
    subversion/trunk/subversion/libsvn_subr/opt.h
    subversion/trunk/subversion/libsvn_subr/sysinfo.c
    subversion/trunk/subversion/libsvn_subr/sysinfo.h

Modified: subversion/trunk/subversion/libsvn_subr/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/deprecated.c?rev=1380559&r1=1380558&r2=1380559&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_subr/deprecated.c Tue Sep  4 11:22:59 2012
@@ -605,9 +605,9 @@ svn_opt_print_help(apr_getopt_t *os,
     }
   else if (print_version)   /* just --version */
     {
-      const char *info = svn_opt__get_version_info(pgm_name, version_footer,
-                                                   quiet, FALSE, pool);
-      SVN_ERR(svn_cmdline_fputs(info, stdout, pool));
+      SVN_ERR(svn_opt__print_version_info(pgm_name, version_footer,
+                                          svn_opt__get_version_info(pool),
+                                          quiet, FALSE, pool));
     }
   else if (os && !targets->nelts)            /* `-h', `--help', or `help' */
     svn_opt_print_generic_help(header,

Modified: subversion/trunk/subversion/libsvn_subr/opt.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.c?rev=1380559&r1=1380558&r2=1380559&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.c (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.c Tue Sep  4 11:22:59 2012
@@ -1103,67 +1103,113 @@ svn_opt__arg_canonicalize_path(const cha
 }
 
 
-const char *
-svn_opt__get_version_info(const char *pgm_name,
-                          const char *footer,
-                          svn_boolean_t quiet,
-                          svn_boolean_t verbose,
-                          apr_pool_t *pool)
+const svn_opt__version_info_t *
+svn_opt__get_version_info(apr_pool_t *pool)
 {
-  char *info;
+  svn_opt__version_info_t *info = apr_pcalloc(pool, sizeof(*info));
 
+  info->version_number = SVN_VER_NUMBER;
+  info->version_string =  SVN_VERSION;
+  info->build_date = __DATE__;
+  info->build_time = __TIME__;
+  info->build_host = SVN_BUILD_HOST;
+  info->copyright = apr_pstrdup
+    (pool, _("Copyright (C) 2012 The Apache Software Foundation.\n"
+             "This software consists of contributions made by many "
+             "people; see the NOTICE\n"
+             "file for more information.\n"
+             "Subversion is open source software, see "
+             "http://subversion.apache.org/\n"));
+  info->runtime_host = svn_sysinfo__canonical_host(pool);
+  info->runtime_osname = svn_sysinfo__release_name(pool);
+  info->linked_libs = svn_sysinfo__linked_libs(pool);
+  info->loaded_libs = svn_sysinfo__loaded_libs(pool);
+
+  return info;
+}
+
+
+svn_error_t *
+svn_opt__print_version_info(const char *pgm_name,
+                            const char *footer,
+                            const svn_opt__version_info_t *info,
+                            svn_boolean_t quiet,
+                            svn_boolean_t verbose,
+                            apr_pool_t *pool)
+{
   if (quiet)
-    return apr_psprintf(pool, "%s\n", SVN_VER_NUMBER);
+    return svn_cmdline_printf(pool, "%s\n", info->version_number);
 
-  info = apr_psprintf(pool, _("%s, version %s\n"
-                              "   compiled %s, %s on %s\n\n"),
-                      pgm_name, SVN_VERSION, __DATE__, __TIME__,
-                      SVN_BUILD_HOST);
-  info = apr_pstrcat(pool, info,
-                     _("Copyright (C) 2012 The Apache Software Foundation.\n"
-                       "This software consists of contributions made by many "
-                       "people; see the NOTICE\n"
-                       "file for more information.\n"
-                       "Subversion is open source software, see "
-                       "http://subversion.apache.org/\n\n"),
-                     NULL);
+  SVN_ERR(svn_cmdline_printf(pool, _("%s, version %s\n"
+                                     "   compiled %s, %s on %s\n\n"),
+                             pgm_name, info->version_string,
+                             info->build_date, info->build_time,
+                             info->build_host));
+  SVN_ERR(svn_cmdline_printf(pool, "%s\n", info->copyright));
 
   if (footer)
     {
-      info = apr_pstrcat(pool, info, footer, "\n", NULL);
+      SVN_ERR(svn_cmdline_printf(pool, "%s\n", footer));
     }
 
   if (verbose)
     {
-      const char *const host = svn_sysinfo__canonical_host(pool);
-      const char *const relname = svn_sysinfo__release_name(pool);
-      const char *const slibs = svn_sysinfo__linked_libs(pool);
-      const char *const dlibs = svn_sysinfo__loaded_libs(pool);
-
-      info = apr_pstrcat(pool, info, _("System information:\n\n"), NULL);
-      if (relname)
-        info = apr_psprintf(pool, _("%s* running on %s\n"
-                                    "  - %s\n"),
-                            info, host, relname);
-      else
-        info = apr_psprintf(pool, _("%s* running on %s\n"), info, host);
+      SVN_ERR(svn_cmdline_fputs(_("System information:\n\n"), stdout, pool));
+      SVN_ERR(svn_cmdline_printf(pool, _("* running on %s\n"),
+                                 info->runtime_host));
+      if (info->runtime_osname)
+        {
+          SVN_ERR(svn_cmdline_printf(pool, _("  - %s\n"),
+                                     info->runtime_osname));
+        }
 
-      if (slibs)
+      if (info->linked_libs && info->linked_libs->nelts)
         {
-          info = apr_pstrcat(pool, info,
-                             _("* linked dependencies:\n"),
-                             slibs, NULL);
+          const svn_sysinfo__linked_lib_t *lib;
+          int i;
+
+          SVN_ERR(svn_cmdline_fputs(_("* linked dependencies:\n"),
+                                    stdout, pool));
+          for (i = 0; i < info->linked_libs->nelts; ++i)
+            {
+              lib = &APR_ARRAY_IDX(info->linked_libs, i,
+                                   svn_sysinfo__linked_lib_t);
+              if (lib->runtime_version)
+                SVN_ERR(svn_cmdline_printf(pool,
+                                           "  - %s %s (compiled with %s)\n",
+                                           lib->name,
+                                           lib->runtime_version,
+                                           lib->compiled_version));
+              else
+                SVN_ERR(svn_cmdline_printf(pool,
+                                           "  - %s %s (static)\n",
+                                           lib->name,
+                                           lib->compiled_version));
+            }
         }
 
-      if (dlibs)
+      if (info->loaded_libs && info->loaded_libs->nelts)
         {
-          info = apr_pstrcat(pool, info,
-                             _("* loaded shared libraries:\n"),
-                             dlibs, NULL);
+          const svn_sysinfo__loaded_lib_t *lib;
+          int i;
+
+          SVN_ERR(svn_cmdline_fputs(_("* loaded shared libraries:\n"),
+                                    stdout, pool));
+          for (i = 0; i < info->loaded_libs->nelts; ++i)
+            {
+              lib = &APR_ARRAY_IDX(info->loaded_libs, i,
+                                   svn_sysinfo__loaded_lib_t);
+              if (lib->version)
+                SVN_ERR(svn_cmdline_printf(pool,
+                                           "  - %s   (%s)\n",
+                                           lib->name, lib->version));
+              else
+                SVN_ERR(svn_cmdline_printf(pool, "  - %s\n", lib->name));
+            }
         }
     }
 
-  return info;
+  return SVN_NO_ERROR;
 }
 
 svn_error_t *
@@ -1198,9 +1244,9 @@ svn_opt_print_help4(apr_getopt_t *os,
     }
   else if (print_version)   /* just --version */
     {
-      const char *info = svn_opt__get_version_info(pgm_name, version_footer,
-                                                   quiet, verbose, pool);
-      SVN_ERR(svn_cmdline_fputs(info, stdout, pool));
+      SVN_ERR(svn_opt__print_version_info(pgm_name, version_footer,
+                                          svn_opt__get_version_info(pool),
+                                          quiet, verbose, pool));
     }
   else if (os && !targets->nelts)            /* `-h', `--help', or `help' */
     svn_opt_print_generic_help2(header,

Modified: subversion/trunk/subversion/libsvn_subr/opt.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.h?rev=1380559&r1=1380558&r2=1380559&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.h (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.h Tue Sep  4 11:22:59 2012
@@ -24,25 +24,58 @@
 #ifndef SVN_LIBSVN_SUBR_OPT_H
 #define SVN_LIBSVN_SUBR_OPT_H
 
+#include <apr_tables.h>
 #include "svn_opt.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
-/* Return a string containing version info for PGM_NAME.  If QUIET is
+
+/* This structure stores the available information about the version,
+ * build and runtime environment of the Subversion client libraries.
+ */
+typedef struct svn_opt__version_info_t svn_opt__version_info_t;
+struct svn_opt__version_info_t
+{
+  const char *version_number;   /* version number */
+  const char *version_string;   /* version string */
+  const char *build_date;       /* compilation date */
+  const char *build_time;       /* compilation time */
+  const char *build_host;       /* nuild canonical host name */
+  const char *copyright;        /* vopyright notice */
+  const char *runtime_host;     /* runtime canonical host name */
+  const char *runtime_osname;   /* running OS release name */
+
+  /* Array svn_sysinfo__linked_lib_t describing dependent libraries */
+  const apr_array_header_t *linked_libs;
+
+  /* Array of svn_sysinfo__loaded_lib_t describing loaded shared libraries */
+  const apr_array_header_t *loaded_libs;
+};
+
+
+/* Return version information for the running program, allocated from POOL.
+ *
+ * Use POOL for temporary allocations.
+ */
+const svn_opt__version_info_t *
+svn_opt__get_version_info(apr_pool_t *pool);
+
+/* Print version version info for PGM_NAME to the console.  If QUIET is
  * true, print in brief.  Else if QUIET is not true, print the version
  * more verbosely, and if FOOTER is non-null, print it following the
  * version information. If VERBOSE is true, print running system info.
  *
  * Use POOL for temporary allocations.
  */
-const char *
-svn_opt__get_version_info(const char *pgm_name,
-                          const char *footer,
-                          svn_boolean_t quiet,
-                          svn_boolean_t verbose,
-                          apr_pool_t *pool);
+svn_error_t *
+svn_opt__print_version_info(const char *pgm_name,
+                            const char *footer,
+                            const svn_opt__version_info_t *info,
+                            svn_boolean_t quiet,
+                            svn_boolean_t verbose,
+                            apr_pool_t *pool);
 
 #ifdef __cplusplus
 }

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.c?rev=1380559&r1=1380558&r2=1380559&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.c Tue Sep  4 11:22:59 2012
@@ -59,13 +59,15 @@
 
 #if HAVE_UNAME
 static const char* canonical_host_from_uname(apr_pool_t *pool);
+# ifndef SVN_HAVE_MACOS_PLIST
 static const char* release_name_from_uname(apr_pool_t *pool);
+# endif
 #endif
 
 #ifdef WIN32
 static const char * win32_canonical_host(apr_pool_t *pool);
 static const char * win32_release_name(apr_pool_t *pool);
-static const char * win32_shared_libs(apr_pool_t *pool);
+static const apr_array_header_t *win32_shared_libs(apr_pool_t *pool);
 #endif /* WIN32 */
 
 #ifdef SVN_HAVE_MACOS_PLIST
@@ -100,30 +102,35 @@ svn_sysinfo__release_name(apr_pool_t *po
 #endif
 }
 
-const char *
+const apr_array_header_t *
 svn_sysinfo__linked_libs(apr_pool_t *pool)
 {
-  const char *apr_ver =
-    apr_psprintf(pool, "APR %s (compiled with %s)",
-                 apr_version_string(), APR_VERSION_STRING);
-  const char *apr_util_ver =
-    apr_psprintf(pool, "APR-Util %s (compiled with %s)",
-                 apu_version_string(), APU_VERSION_STRING);
-  const char *sqlite_ver =
+  svn_sysinfo__linked_lib_t *lib;
+  apr_array_header_t *array = apr_array_make(pool, 3, sizeof(*lib));
+
+  lib = &APR_ARRAY_PUSH(array, svn_sysinfo__linked_lib_t);
+  lib->name = "APR";
+  lib->compiled_version = APR_VERSION_STRING;
+  lib->runtime_version = apr_pstrdup(pool, apr_version_string());
+
+  lib = &APR_ARRAY_PUSH(array, svn_sysinfo__linked_lib_t);
+  lib->name = "APR-Util";
+  lib->compiled_version = APU_VERSION_STRING;
+  lib->runtime_version = apr_pstrdup(pool, apu_version_string());
+
+  lib = &APR_ARRAY_PUSH(array, svn_sysinfo__linked_lib_t);
+  lib->name = "SQLite";
+  lib->compiled_version = apr_pstrdup(pool, svn_sqlite__compiled_version());
 #ifdef SVN_SQLITE_INLINE
-    apr_psprintf(pool, "SQLite %s (amalgamated)",
-                 svn_sqlite__runtime_version());
+  lib->runtime_version = NULL;
 #else
-    apr_psprintf(pool, "SQLite %s (compiled with %s)",
-                 svn_sqlite__runtime_version(),
-                 svn_sqlite__compiled_version());
+  lib->runtime_version = apr_pstrdup(pool, svn_sqlite__runtime_version());
 #endif
 
-    return apr_psprintf(pool, "  - %s\n  - %s\n  - %s\n",
-                        apr_ver, apr_util_ver, sqlite_ver);
+  return array;
 }
 
-const char *
+const apr_array_header_t *
 svn_sysinfo__loaded_libs(apr_pool_t *pool)
 {
 #ifdef WIN32
@@ -198,6 +205,7 @@ canonical_host_from_uname(apr_pool_t *po
   return apr_psprintf(pool, "%s-%s-%s%s", machine, vendor, sysname, sysver);
 }
 
+# if !SVN_HAVE_MACOS_PLIST
 /* Generate a release name from the uname(3) info, effectively
    returning "`uname -s` `uname -r`". */
 static const char *
@@ -235,6 +243,7 @@ release_name_from_uname(apr_pool_t *pool
     }
   return NULL;
 }
+# endif  /* !SVN_HAVE_MACOS_PLIST */
 #endif  /* HAVE_UNAME */
 
 
@@ -513,12 +522,12 @@ file_version_number(const wchar_t *filen
 }
 
 /* List the shared libraries loaded by the current process. */
-static const char *
+static const apr_array_header_t *
 win32_shared_libs(apr_pool_t *pool)
 {
+  apr_array_header_t *array = NULL;
   wchar_t buffer[MAX_PATH + 1];
   HMODULE *handles = enum_loaded_modules(pool);
-  char *libinfo = "";
   HMODULE *module;
 
   for (module = handles; module && *module; ++module)
@@ -532,25 +541,27 @@ win32_shared_libs(apr_pool_t *pool)
           filename = wcs_to_utf8(buffer, pool);
           if (filename)
             {
+              svn_sysinfo__loaded_lib_t *lib;
               char *truename;
+
               if (0 == apr_filepath_merge(&truename, "", filename,
                                           APR_FILEPATH_NATIVE
                                           | APR_FILEPATH_TRUENAME,
                                           pool))
                 filename = truename;
-              if (version)
-                libinfo = apr_pstrcat(pool, libinfo, "  - ", filename,
-                                      "   (", version, ")\n", NULL);
-              else
-                libinfo = apr_pstrcat(pool, libinfo, "  - ", filename,
-                                      "\n", NULL);
+
+              if (!array)
+                {
+                  array = apr_array_make(pool, 32, sizeof(*lib));
+                }
+              lib = &APR_ARRAY_PUSH(array, svn_sysinfo__loaded_lib_t);
+              lib->name = filename;
+              lib->version = version;
             }
         }
     }
 
-  if (*libinfo)
-    return libinfo;
-  return NULL;
+  return array;
 }
 #endif /* WIN32 */
 

Modified: subversion/trunk/subversion/libsvn_subr/sysinfo.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sysinfo.h?rev=1380559&r1=1380558&r2=1380559&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sysinfo.h (original)
+++ subversion/trunk/subversion/libsvn_subr/sysinfo.h Tue Sep  4 11:22:59 2012
@@ -25,11 +25,13 @@
 #define SVN_LIBSVN_SUBR_SYSINFO_H
 
 #include <apr_pools.h>
+#include <apr_tables.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
+
 /* Return a canonical name similar to the output of config.guess,
  * identifying the running system.
  *
@@ -44,20 +46,39 @@ const char *svn_sysinfo__canonical_host(
  */
 const char *svn_sysinfo__release_name(apr_pool_t *pool);
 
-/* Return a description of the link-time and run-time versions of
- * dependent libraries.
+/* Describes a linked dependency library */
+typedef struct svn_sysinfo__linked_lib_t svn_sysinfo__linked_lib_t;
+struct svn_sysinfo__linked_lib_t
+{
+  const char *name;             /* library name */
+  const char *compiled_version; /* compile-time version string */
+  const char *runtime_version;  /* run-time version string (optional) */
+};
+
+/* Return an array of svn_sysinfo__linked_lib_t of descriptions of the
+ * link-time and run-time versions of dependent libraries, or NULL of
+ * the info is not available.
  *
  * All allocations are done in POOL.
  */
-const char *svn_sysinfo__linked_libs(apr_pool_t *pool);
+const apr_array_header_t *svn_sysinfo__linked_libs(apr_pool_t *pool);
 
-/* Return a string containing a list of shared libraries loaded by the
- * running process, including their versions where applicable, or NULL
- * if the information is not available.
+/* Describes a loaded shared library */
+typedef struct svn_sysinfo__loaded_lib_t svn_sysinfo__loaded_lib_t;
+struct svn_sysinfo__loaded_lib_t
+{
+  const char *name;             /* library name */
+  const char *version;          /* library version (optional) */
+};
+
+/* Return an array of svn_sysinfo__loaded_lib_t of descriptions of
+ * shared libraries loaded by the running process, including their
+ * versions where applicable, or NULL if the information is not
+ * available.
  *
  * All allocations are done in POOL.
  */
-const char *svn_sysinfo__loaded_libs(apr_pool_t *pool);
+const apr_array_header_t *svn_sysinfo__loaded_libs(apr_pool_t *pool);
 
 #ifdef __cplusplus
 }