"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
histedit: fix editing of log message comments
To:
gameoftrees@openbsd.org
Date:
Wed, 16 Dec 2020 00:26:27 +0100

Download raw body.

Thread
While editing history, I somehow ended up with a commit which had a
log message that looked something like this:

[[[
# original log message of commit 2c3671a064b1cb21a5b8ebfa84914a8f246f8dcc:
# original log message of commit 486a0d8c8af15488d38b605319ea63aa98df255c:
# original log message of commit 228dc1c47acd2b...

actual log message text here
]]]

I then tried to use 'got he -m' to remove just those "original log message"
comment lines, leaving the rest of the log message text intact.

Turns out that 'got he' treats the log message as unmodified in this case,
and copies the message as-is, keeping the comments intact. This behaviour
was coded to prevent mistakes during 'got commit/import/tag', where the
command will error out if the log message template is not modified. This is
not appropriate for histedit because histedit is used to fix such mistakes.

With the patch below applied, I could remove the comments with 'got he -m'.

ok?

diff 2ec5b3604b0907fe87969d9929f01f4339627a19 6c16f62b79d387a06e7850ae7e194d71f1f1e4eb
blob - 6d427879bfb75db1dd06c1c4b0eb326ddd18ffc0
blob + a25e4752c753ed41ccef89d82be94cb91863bc50
--- got/got.c
+++ got/got.c
@@ -431,7 +431,7 @@ doneediting:
 
 static const struct got_error *
 edit_logmsg(char **logmsg, const char *editor, const char *logmsg_path,
-    const char *initial_content, size_t initial_content_len)
+    const char *initial_content, size_t initial_content_len, int check_comments)
 {
 	const struct got_error *err = NULL;
 	char *line = NULL;
@@ -526,7 +526,7 @@ edit_logmsg(char **logmsg, const char *editor, const c
 		    "commit message cannot be empty, aborting");
 		goto done;
 	}
-	if (strcmp(*logmsg, initial_content_stripped) == 0)
+	if (check_comments && strcmp(*logmsg, initial_content_stripped) == 0)
 		err = got_error_msg(GOT_ERR_COMMIT_MSG_EMPTY,
 		    "no changes made to commit message, aborting");
 done:
@@ -567,7 +567,7 @@ collect_import_msg(char **logmsg, char **logmsg_path, 
 	}
 
 	err = edit_logmsg(logmsg, editor, *logmsg_path, initial_content,
-	    initial_content_len);
+	    initial_content_len, 1);
 done:
 	if (fd != -1 && close(fd) == -1 && err == NULL)
 		err = got_error_from_errno2("close", *logmsg_path);
@@ -5901,7 +5901,7 @@ get_tag_message(char **tagmsg, char **tagmsg_path, con
 	if (err)
 		goto done;
 	err = edit_logmsg(tagmsg, editor, *tagmsg_path, initial_content,
-	    initial_content_len);
+	    initial_content_len, 1);
 done:
 	free(initial_content);
 	free(template);
@@ -6782,7 +6782,7 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 	}
 
 	err = edit_logmsg(logmsg, a->editor, a->logmsg_path, initial_content,
-	    initial_content_len);
+	    initial_content_len, 1);
 done:
 	free(initial_content);
 	free(template);
@@ -8020,7 +8020,7 @@ histedit_edit_logmsg(struct got_histedit_list_entry *h
 		goto done;
 
 	err = edit_logmsg(&hle->logmsg, editor, logmsg_path, logmsg,
-	    logmsg_len);
+	    logmsg_len, 0);
 	if (err) {
 		if (err->code != GOT_ERR_COMMIT_MSG_EMPTY)
 			goto done;