Commit 0d5bb27670e5cdef181f8073984fd02be5a42d53

Stefan Sperling 2020-12-15T23:50:35

allow editing of log message comments with 'got histedit' This makes it possible to remove just comment lines from log messages during a histedit operation, leaving the rest of the log message as-is. The behaviour of treating changes to comment lines as no-ops 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. ok millert@

diff --git a/got/got.c b/got/got.c
index 6d42787..a25e475 100644
--- a/got/got.c
+++ b/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 char *logmsg_path,
 		    "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, const char *editor,
 	}
 
 	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, const char *commit_id_str,
 	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 *commitable_paths, char **logmsg,
 	}
 
 	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 *hle,
 		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;