Download raw body.
No-op histedit scripts
Christian Weisgerber <naddy@mips.inka.de> wrote:
> Mark Jamsek:
>
> > > +If the temporary file is not written to, the import operation is aborted.
> >
> > I think you've stated the caveat well; it's clear and concise. I like it!
> > Using the same verb and noun as in the preceding sentence makes it
> > simple to understand the abort condition.
>
> Still, here's an alternative idea:
>
> "Quitting the editor without saving the file will abort the [...]
> operation."
Yes, that reads nicer than your previous attempt! And the condition is
equally, if not more, clear.
ok
> diff refs/heads/main refs/heads/histedit
> commit - 1494a06e4ce25cf1beafa90b6b1f98bdebf9e7e2
> commit + 6f6ae83d2af4d9b05b321737b4205120ffea351e
> blob - ea3b833f1bc15d5ea3e276e75da0a16f1e29702c
> blob + 19956b285901018b3d037f8f9a305d91091998ff
> --- got/got.1
> +++ got/got.1
> @@ -127,6 +127,7 @@ opens a temporary file in an editor where a log messag
> option,
> .Cm got import
> opens a temporary file in an editor where a log message can be written.
> +Quitting the editor without saving the file will abort the import operation.
> .It Fl r Ar repository-path
> Use the repository at the specified path.
> If not specified, assume the repository is located at or above the current
> @@ -1347,6 +1348,7 @@ opens a temporary file in an editor where a tag messag
> option,
> .Cm got tag
> opens a temporary file in an editor where a tag message can be written.
> +Quitting the editor without saving the file will abort the tag operation.
> .It Fl r Ar repository-path
> Use the repository at the specified path.
> If not specified, assume the repository is located at or above the current
> @@ -1708,6 +1710,7 @@ options are used together.
> and
> .Fl N
> options are used together.
> +Quitting the editor without saving the file will abort the commit operation.
> .Pp
> Show the status of each affected file, using the following status codes:
> .Bl -column YXZ description
> @@ -2522,6 +2525,7 @@ options.
> or
> .Fl m
> options.
> +Quitting the editor without saving the file will abort the histedit operation.
> .Pp
> The format of the histedit script is line-based.
> Each line in the script begins with a command name, followed by
> blob - e21a92523011eaf67089838f68f9e98950704b11
> blob + 2a5d0bd5f3e513f26cad87624b5c5ebbb8eaef14
> --- got/got.c
> +++ got/got.c
> @@ -11969,6 +11969,8 @@ histedit_run_editor(struct got_histedit_list *histedit
> struct got_repository *repo)
> {
> const struct got_error *err = NULL;
> + struct stat st, st2;
> + struct timespec timeout;
> char *editor;
> FILE *f = NULL;
>
> @@ -11976,11 +11978,32 @@ histedit_run_editor(struct got_histedit_list *histedit
> if (err)
> return err;
>
> + if (stat(path, &st) == -1) {
> + err = got_error_from_errno2("stat", path);
> + goto done;
> + }
> +
> if (spawn_editor(editor, path) == -1) {
> err = got_error_from_errno("failed spawning editor");
> goto done;
> }
>
> + timeout.tv_sec = 0;
> + timeout.tv_nsec = 1;
> + nanosleep(&timeout, NULL);
> +
> + if (stat(path, &st2) == -1) {
> + err = got_error_from_errno2("stat", path);
> + goto done;
> + }
> +
> + if (st.st_size == st2.st_size &&
> + timespeccmp(&st.st_mtim, &st2.st_mtim, ==)) {
> + err = got_error_msg(GOT_ERR_EMPTY_HISTEDIT,
> + "no changes made to histedit script, aborting");
> + goto done;
> + }
> +
> f = fopen(path, "re");
> if (f == NULL) {
> err = got_error_from_errno("fopen");
--
Mark Jamsek <https://bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
No-op histedit scripts