Paul Eggert wrote: > > - If F is under version control and not modified locally: > > the time of the last change of F in the version control system. > > It's worth mentioning that in Git, this is the commit timestamp and not > the author timestamp.
Done through the first of the patches below. > Why is this a C program and not a shell script? A script would be easier > to maintain. That's worth commenting on, at least. For my use as part of 'xgettext', I need a C program - for portability, since xgettext is meant to work on native Windows, - for speed, since the 2 git subprocesses per file are already enough of a slowdown; I don't need extra runtime overhead of a shell. If someone needs the functionality as part of the build system, feel free to add a module 'vc-mtime-script' that implements the same thing within a few lines of /bin/sh script. 2025-02-25 Bruno Haible <br...@clisp.org> csharpcomp: Reduce number of read() system calls. * lib/csharpcomp.c: Include <stddef.h>. (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. 2025-02-25 Bruno Haible <br...@clisp.org> vc-mtime: Reduce number of read() system calls. * lib/vc-mtime.c: Include <stddef.h>. (git_vc_controlled): Read bytes into a buffer, not one-by-one. 2025-02-25 Bruno Haible <br...@clisp.org> vc-mtime: Improve comment. Suggested by Paul Eggert. * lib/vc-mtime.c (git_mtime): Clarify CommitDate vs. AuthorDate.
>From 399d9dce562a909ae493a591371e0a6c83518182 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 25 Feb 2025 09:19:52 +0100 Subject: [PATCH 1/3] vc-mtime: Improve comment. Suggested by Paul Eggert. * lib/vc-mtime.c (git_mtime): Clarify CommitDate vs. AuthorDate. --- ChangeLog | 6 ++++++ lib/vc-mtime.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3e170e5117..dfea4e0e6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-02-25 Bruno Haible <br...@clisp.org> + + vc-mtime: Improve comment. + Suggested by Paul Eggert. + * lib/vc-mtime.c (git_mtime): Clarify CommitDate vs. AuthorDate. + 2025-02-24 Bruno Haible <br...@clisp.org> vc-mtime: New module. diff --git a/lib/vc-mtime.c b/lib/vc-mtime.c index 0f333d5b6b..0e609033f6 100644 --- a/lib/vc-mtime.c +++ b/lib/vc-mtime.c @@ -102,7 +102,9 @@ static int git_mtime (struct timespec *mtime, const char *filename) { /* Run "git log -1 --format=%ct -- FILENAME". It prints the time of last - modification, as the number of seconds since the Epoch. + modification (the 'CommitDate', not the 'AuthorDate' which merely + represents the time at which the author locally committed the first version + of the change), as the number of seconds since the Epoch. The '--' option is for the case that the specified file was removed. */ const char *argv[7]; pid_t child; -- 2.43.0
>From 60cd34886c2c9f509974239fcf64a61f9a507d14 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 25 Feb 2025 09:04:28 +0100 Subject: [PATCH 2/3] vc-mtime: Reduce number of read() system calls. * lib/vc-mtime.c: Include <stddef.h>. (git_vc_controlled): Read bytes into a buffer, not one-by-one. --- ChangeLog | 6 ++++++ lib/vc-mtime.c | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfea4e0e6e..af7413ee5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-02-25 Bruno Haible <br...@clisp.org> + + vc-mtime: Reduce number of read() system calls. + * lib/vc-mtime.c: Include <stddef.h>. + (git_vc_controlled): Read bytes into a buffer, not one-by-one. + 2025-02-25 Bruno Haible <br...@clisp.org> vc-mtime: Improve comment. diff --git a/lib/vc-mtime.c b/lib/vc-mtime.c index 0e609033f6..f80bd77b69 100644 --- a/lib/vc-mtime.c +++ b/lib/vc-mtime.c @@ -21,6 +21,7 @@ /* Specification. */ #include "vc-mtime.h" +#include <stddef.h> #include <stdlib.h> #include <unistd.h> @@ -56,11 +57,17 @@ git_vc_controlled (const char *filename) return false; /* Read the subprocess output, and test whether it is non-empty. */ - size_t count = 0; - char c; + ptrdiff_t count = 0; - while (safe_read (fd[0], &c, 1) > 0) - count++; + for (;;) + { + char buf[1024]; + ptrdiff_t n = safe_read (fd[0], buf, sizeof (buf)); + if (n > 0) + count += n; + else + break; + } close (fd[0]); -- 2.43.0
>From f703b5434b1eb02c483f631fe23368130ebc3e07 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 25 Feb 2025 09:04:45 +0100 Subject: [PATCH 3/3] csharpcomp: Reduce number of read() system calls. * lib/csharpcomp.c: Include <stddef.h>. (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. --- ChangeLog | 6 ++++++ lib/csharpcomp.c | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index af7413ee5e..4ece515f20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-02-25 Bruno Haible <br...@clisp.org> + + csharpcomp: Reduce number of read() system calls. + * lib/csharpcomp.c: Include <stddef.h>. + (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. + 2025-02-25 Bruno Haible <br...@clisp.org> vc-mtime: Reduce number of read() system calls. diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c index ad74604dd8..5b6c9684d9 100644 --- a/lib/csharpcomp.c +++ b/lib/csharpcomp.c @@ -23,6 +23,7 @@ #include <dirent.h> #include <errno.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -311,11 +312,17 @@ compile_csharp_using_dotnet (const char * const *sources, { /* Read the subprocess output, and test whether it is non-empty. */ - size_t count = 0; - char c; + ptrdiff_t count = 0; - while (safe_read (fd[0], &c, 1) > 0) - count++; + for (;;) + { + char buf[1024]; + ptrdiff_t n = safe_read (fd[0], buf, sizeof (buf)); + if (n > 0) + count += n; + else + break; + } close (fd[0]); -- 2.43.0