]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Speed up the computation of the POT-Creation-Date.
authorBruno Haible <bruno@clisp.org>
Thu, 1 May 2025 22:45:01 +0000 (00:45 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 May 2025 00:46:11 +0000 (02:46 +0200)
Reported by Serhii Tereshchenko, Arthur, Adam YS, Foucauld Degeorges
at <https://savannah.gnu.org/bugs/?66865>.

* gettext-tools/src/xgettext.c (has_some_mtimes, max_of_mtimes, some_mtimes_failed): Remove variables.
(files_for_vc_mtime): New variable.
(main): Initialize files_for_vc_mtime. Update files_for_vc_mtime instead of calling consider_vc_mtime.
(consider_vc_mtime): Remove function.
(read_exclusion_file, extract_from_file, extract_from_xml_file): Update files_for_vc_mtime instead of calling consider_vc_mtime.
(finalize_header): Call max_vc_mtime.
* NEWS: Mention the speedup.

NEWS
gettext-tools/src/xgettext.c

diff --git a/NEWS b/NEWS
index d630fc9aa32fc440e77f671d1d91c1b99c5566ea..236f65db268b8c6cb77a29ddd78d15e98acfbc70 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-Version 0.25 - April 2025
+Version 0.25 - May 2025
 
 # Programming languages support:
   * Go:
@@ -24,10 +24,12 @@ Version 0.25 - April 2025
       strings.
     - A new example 'hello-modula2' has been added.
 
-Version 0.24.1 - April 2025
+Version 0.24.1 - May 2025
 
 * Bug fixes:
   - Fix bad interactions between autoreconf and autopoint.
+  - xgettext: Creating the POT file of a package under Git version control
+    is now faster.
 
 Version 0.24 - February 2025
 
index 1f9ca50d63925f88f8407135bf1fd0e767ffd68b..0c1471f8decf23b4981d84a92e9f60a21f09b463 100644 (file)
@@ -244,10 +244,9 @@ static locating_rule_list_ty *its_locating_rules;
 /* If nonzero add comments used by itstool.  */
 static bool add_itstool_comments = false;
 
-/* Accumulating the version-controlled modification times of file names.  */
-static bool has_some_mtimes = false;
-static struct timespec max_of_mtimes;
-static bool some_mtimes_failed = false;
+/* The file names whose version-controlled modification times shall be
+   considered.  */
+static string_list_ty files_for_vc_mtime;
 
 /* Long options.  */
 static const struct option long_options[] =
@@ -337,7 +336,6 @@ struct extractor_ty
 /* Forward declaration of local functions.  */
 _GL_NORETURN_FUNC static void usage (int status);
 static void read_exclusion_file (char *file_name);
-static void consider_vc_mtime (const char *file_name);
 static void extract_from_file (const char *file_name, extractor_ty extractor,
                                msgdomain_list_ty *mdlp);
 static void extract_from_xml_file (const char *file_name,
@@ -392,6 +390,7 @@ main (int argc, char *argv[])
 
   /* Set initial value of variables.  */
   default_domain = MESSAGE_DOMAIN_DEFAULT;
+  string_list_init (&files_for_vc_mtime);
   xgettext_global_source_encoding = NULL;
   init_flag_table_c ();
   init_flag_table_objc ();
@@ -729,7 +728,7 @@ main (int argc, char *argv[])
         break;
 
       case CHAR_MAX + 22: /* --reference */
-        consider_vc_mtime (optarg);
+        string_list_append (&files_for_vc_mtime, optarg);
         break;
 
       default:
@@ -848,7 +847,7 @@ xgettext cannot work without keywords to look for"));
   if (files_from != NULL)
     {
       if (strcmp (files_from, "-") != 0)
-        consider_vc_mtime (files_from);
+        string_list_append (&files_for_vc_mtime, files_from);
       file_list = read_names_from_file (files_from);
     }
   else
@@ -1337,29 +1336,6 @@ or by email to <%s>.\n"),
 }
 
 
-static void
-consider_vc_mtime (const char *file_name)
-{
-  struct timespec mtime;
-  if (vc_mtime (&mtime, file_name) >= 0)
-    {
-      if (has_some_mtimes)
-        {
-          /* Compute the maximum of max_of_mtimes and mtime.  */
-          if (max_of_mtimes.tv_sec < mtime.tv_sec
-              || (max_of_mtimes.tv_sec == mtime.tv_sec
-                  && max_of_mtimes.tv_nsec < mtime.tv_nsec))
-           max_of_mtimes = mtime;
-        }
-      else
-        max_of_mtimes = mtime;
-    }
-  else
-    some_mtimes_failed = true;
-  has_some_mtimes = true;
-}
-
-
 static void
 exclude_directive_domain (abstract_catalog_reader_ty *catr,
                           char *name, lex_pos_ty *name_pos)
@@ -1432,7 +1408,7 @@ read_exclusion_file (char *filename)
   char *real_filename;
   FILE *fp = open_catalog_file (filename, &real_filename, true);
 
-  consider_vc_mtime (real_filename);
+  string_list_append (&files_for_vc_mtime, real_filename);
 
   abstract_catalog_reader_ty *catr =
     catalog_reader_alloc (&exclude_methods, textmode_xerror_handler);
@@ -2073,7 +2049,7 @@ extract_from_file (const char *file_name, extractor_ty extractor,
     {
       FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
       if (fp != stdin)
-        consider_vc_mtime (real_file_name);
+        string_list_append (&files_for_vc_mtime, real_file_name);
 
       /* Set the default for the source file encoding.  May be overridden by
          the extractor function.  */
@@ -2095,7 +2071,7 @@ extract_from_file (const char *file_name, extractor_ty extractor,
       const char *found_in_dir;
       xgettext_find_file (file_name, &logical_file_name,
                           &found_in_dir, &real_file_name);
-      consider_vc_mtime (real_file_name);
+      string_list_append (&files_for_vc_mtime, real_file_name);
 
       extractor.extract_from_file (found_in_dir, real_file_name,
                                    logical_file_name,
@@ -2148,7 +2124,7 @@ extract_from_xml_file (const char *file_name,
   char *real_file_name;
   FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
   if (fp != stdin)
-    consider_vc_mtime (real_file_name);
+    string_list_append (&files_for_vc_mtime, real_file_name);
 
   /* The default encoding for XML is UTF-8.  It can be overridden by
      an XML declaration in the XML file itself, not through the
@@ -2165,7 +2141,7 @@ extract_from_xml_file (const char *file_name,
 
   if (fp != stdin)
     fclose (fp);
-  consider_vc_mtime (real_file_name);
+  string_list_append (&files_for_vc_mtime, real_file_name);
   free (logical_file_name);
   free (real_file_name);
 }
@@ -2252,7 +2228,11 @@ finalize_header (msgdomain_list_ty *mdlp)
   /* Set the POT-Creation-Date field.  */
   {
     time_t stamp;
-    if (has_some_mtimes && !some_mtimes_failed)
+    struct timespec max_of_mtimes;
+    if (files_for_vc_mtime.nitems > 0
+        && max_vc_mtime (&max_of_mtimes,
+                         files_for_vc_mtime.nitems, files_for_vc_mtime.item)
+           == 0)
       /* Use the maximum of the encountered mtimes.  */
       stamp = max_of_mtimes.tv_sec;
     else