Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Aug 2022 10:49:39 GMT
From:      Renato Botelho <garga@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 82c314474fce - main - devel/git: Fix 'git maintenance start'
Message-ID:  <202208291049.27TAndNf040434@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by garga:

URL: https://cgit.FreeBSD.org/ports/commit/?id=82c314474fce8cd4a9ea5cc95d0ca4f6165e6acc

commit 82c314474fce8cd4a9ea5cc95d0ca4f6165e6acc
Author:     Renato Botelho <garga@FreeBSD.org>
AuthorDate: 2022-08-29 10:15:42 +0000
Commit:     Renato Botelho <garga@FreeBSD.org>
CommitDate: 2022-08-29 10:49:23 +0000

    devel/git: Fix 'git maintenance start'
    
    Add a patch from upstream to fix 'git maintenance start'.  Here follow
    upstream commit message:
    
    While cron is specified by POSIX, there are a wide variety of
    implementations in use.  On FreeBSD, the cron implementation requires a
    file name argument: if the user wants to edit standard input, they must
    specify "-".  However, this notation is not specified by POSIX, allowing
    the possibility that making such a change may break other, less common
    implementations.
    
    Since POSIX tells us that cron must accept a file name argument, let's
    solve this problem by specifying a temporary file instead.  This will
    ensure that we work with the vast majority of implementations.
    
    Note that because delete_tempfile closes the file for us, we should not
    call fclose here on the handle, since doing so will introduce a double
    free.
    
    PR:             260746
    Reported by:    Mark Waite <mark.earl.waite@gmail.com>
    Obtained from:  https://lore.kernel.org/git/1dd29f43-1a8e-eb69-3320-7f5140a0e18e@github.com/T/#me47087c1f9034c82da8eae83db18cc6114c2c1e5
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 devel/git/Makefile                         |   1 +
 devel/git/files/patch-fix-maintenance.diff | 112 +++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)

diff --git a/devel/git/Makefile b/devel/git/Makefile
index b67a43ae469b..19b313cbc33c 100644
--- a/devel/git/Makefile
+++ b/devel/git/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	git
 DISTVERSION=	2.37.2
+PORTREVISION=	1
 CATEGORIES=	devel
 MASTER_SITES=	KERNEL_ORG/software/scm/git
 DISTFILES=	${DISTNAME}${EXTRACT_SUFX} \
diff --git a/devel/git/files/patch-fix-maintenance.diff b/devel/git/files/patch-fix-maintenance.diff
new file mode 100644
index 000000000000..c1ac6dec2452
--- /dev/null
+++ b/devel/git/files/patch-fix-maintenance.diff
@@ -0,0 +1,112 @@
+[PATCH v2] gc: use temporary file for editing crontab
+
+While cron is specified by POSIX, there are a wide variety of
+implementations in use.  On FreeBSD, the cron implementation requires a
+file name argument: if the user wants to edit standard input, they must
+specify "-".  However, this notation is not specified by POSIX, allowing
+the possibility that making such a change may break other, less common
+implementations.
+
+Since POSIX tells us that cron must accept a file name argument, let's
+solve this problem by specifying a temporary file instead.  This will
+ensure that we work with the vast majority of implementations.
+
+Note that because delete_tempfile closes the file for us, we should not
+call fclose here on the handle, since doing so will introduce a double
+free.
+
+Reported-by: Renato Botelho <garga@FreeBSD.org>
+Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
+
+diff --git builtin/gc.c builtin/gc.c
+index eeff2b760e..0d9e6dabef 100644
+--- builtin/gc.c
++++ builtin/gc.c
+@@ -2065,6 +2065,7 @@ static int crontab_update_schedule(int run_maintenance, int fd)
+ 	struct child_process crontab_edit = CHILD_PROCESS_INIT;
+ 	FILE *cron_list, *cron_in;
+ 	struct strbuf line = STRBUF_INIT;
++	struct tempfile *tmpedit = NULL;
+ 
+ 	get_schedule_cmd(&cmd, NULL);
+ 	strvec_split(&crontab_list.args, cmd);
+@@ -2079,6 +2080,17 @@ static int crontab_update_schedule(int run_maintenance, int fd)
+ 	/* Ignore exit code, as an empty crontab will return error. */
+ 	finish_command(&crontab_list);
+ 
++	tmpedit = mks_tempfile_t(".git_cron_edit_tmpXXXXXX");
++	if (!tmpedit) {
++		result = error(_("failed to create crontab temporary file"));
++		goto out;
++	}
++	cron_in = fdopen_tempfile(tmpedit, "w");
++	if (!cron_in) {
++		result = error(_("failed to open temporary file"));
++		goto out;
++	}
++
+ 	/*
+ 	 * Read from the .lock file, filtering out the old
+ 	 * schedule while appending the new schedule.
+@@ -2086,19 +2098,6 @@ static int crontab_update_schedule(int run_maintenance, int fd)
+ 	cron_list = fdopen(fd, "r");
+ 	rewind(cron_list);
+ 
+-	strvec_split(&crontab_edit.args, cmd);
+-	crontab_edit.in = -1;
+-	crontab_edit.git_cmd = 0;
+-
+-	if (start_command(&crontab_edit))
+-		return error(_("failed to run 'crontab'; your system might not support 'cron'"));
+-
+-	cron_in = fdopen(crontab_edit.in, "w");
+-	if (!cron_in) {
+-		result = error(_("failed to open stdin of 'crontab'"));
+-		goto done_editing;
+-	}
+-
+ 	while (!strbuf_getline_lf(&line, cron_list)) {
+ 		if (!in_old_region && !strcmp(line.buf, BEGIN_LINE))
+ 			in_old_region = 1;
+@@ -2132,14 +2131,22 @@ static int crontab_update_schedule(int run_maintenance, int fd)
+ 	}
+ 
+ 	fflush(cron_in);
+-	fclose(cron_in);
+-	close(crontab_edit.in);
+ 
+-done_editing:
++	strvec_split(&crontab_edit.args, cmd);
++	strvec_push(&crontab_edit.args, get_tempfile_path(tmpedit));
++	crontab_edit.git_cmd = 0;
++
++	if (start_command(&crontab_edit)) {
++		result = error(_("failed to run 'crontab'; your system might not support 'cron'"));
++		goto out;
++	}
++
+ 	if (finish_command(&crontab_edit))
+ 		result = error(_("'crontab' died"));
+ 	else
+ 		fclose(cron_list);
++out:
++	delete_tempfile(&tmpedit);
+ 	return result;
+ }
+ 
+diff --git t/helper/test-crontab.c t/helper/test-crontab.c
+index e7c0137a47..2942543046 100644
+--- t/helper/test-crontab.c
++++ t/helper/test-crontab.c
+@@ -17,8 +17,8 @@ int cmd__crontab(int argc, const char **argv)
+ 		if (!from)
+ 			return 0;
+ 		to = stdout;
+-	} else if (argc == 2) {
+-		from = stdin;
++	} else if (argc == 3) {
++		from = fopen(argv[2], "r");
+ 		to = fopen(argv[1], "w");
+ 	} else
+ 		return error("unknown arguments");
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202208291049.27TAndNf040434>