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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: Exclusive log end
To:
Josh Rickmar <joshrickmar@outlook.com>, gameoftrees@openbsd.org
Date:
Sun, 21 Mar 2021 20:31:45 +0100

Download raw body.

Thread
On Sun, Mar 21, 2021 at 08:23:56PM +0100, Stefan Sperling wrote:
> For reference, below is my patch. Please pick whatever you like from it
> and send another version with whatever combination of changes you prefer.
> And if you prefer your patch as-is, then that's fine, too.

Ooops, that patch doesn't apply to main anymore.
Here is a rebased version.

-----------------------------------------------
commit 6e68710c4de235c8037086b38accc2c4e41c67b8 (logX)
from: Stefan Sperling <stsp@stsp.name>
date: Sun Mar 21 19:30:33 2021 UTC
 
 add -X option to 'got log'
 
diff 9271e2e9348b1ac096d2f48ede73ee75ddc346a9 e061aa99fda1d72dc471f58cd7aeb0de669e9242
blob - 22cc9a1eba46d729c6f6890233b894a7d846f716
blob + 16fc3deddbfc30b57408cd976f5db437d3733ea9
--- got/got.1
+++ got/got.1
@@ -717,7 +717,7 @@ in a pattern.
 .It Cm st
 Short alias for
 .Cm status .
-.It Cm log Oo Fl b Oc Oo Fl c Ar commit Oc Oo Fl C Ar number Oc Oo Fl l Ar N Oc Oo Fl p Oc Oo Fl P Oc Oo Fl s Ar search-pattern Oc Oo Fl r Ar repository-path Oc Oo Fl R Oc Oo Fl x Ar commit Oc Op Ar path
+.It Cm log Oo Fl b Oc Oo Fl c Ar commit Oc Oo Fl C Ar number Oc Oo Fl l Ar N Oc Oo Fl p Oc Oo Fl P Oc Oo Fl s Ar search-pattern Oc Oo Fl r Ar repository-path Oc Oo Fl R Oc Oo Fl x Ar commit Oc Oo Fl X Ar commit Oc Op Ar path
 Display history of a repository.
 If a
 .Ar path
@@ -794,10 +794,23 @@ in reverse order.
 .It Fl x Ar commit
 Stop traversing commit history as soon as the specified
 .Ar commit
-has been traversed.
+has been printed.
 This option has no effect if the specified
 .Ar commit
-is never traversed.
+is never encountered.
+Cannot be used together with the
+.Fl X
+option.
+.It Fl X Ar commit
+Stop traversing commit history as soon as the specified
+.Ar commit
+is about to be printed.
+This option has no effect if the specified
+.Ar commit
+is never encountered.
+Cannot be used together with the
+.Fl x
+option.
 .El
 .It Cm diff Oo Fl a Oc Oo Fl C Ar number Oc Oo Fl r Ar repository-path Oc Oo Fl s Oc Oo Fl w Oc Op Ar object1 Ar object2 | Ar path
 When invoked within a work tree with less than two arguments, display
blob - 9bcd279e5446ef8a890025dd5e3e16b3206fc66a
blob + cc48b57ac631471a069d9815b06bb3568221e884
--- got/got.c
+++ got/got.c
@@ -3691,7 +3691,7 @@ static const struct got_error *
 print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
     struct got_repository *repo, const char *path, int show_changed_paths,
     int show_patch, const char *search_pattern, int diff_context, int limit,
-    int log_branches, int reverse_display_order,
+    int log_branches, int reverse_display_order, int traverse_end_commit,
     struct got_reflist_object_id_map *refs_idmap)
 {
 	const struct got_error *err;
@@ -3734,6 +3734,10 @@ print_commits(struct got_object_id *root_id, struct go
 		if (id == NULL)
 			break;
 
+		if (!traverse_end_commit && end_id &&
+		    got_object_id_cmp(id, end_id) == 0)
+			break;
+
 		err = got_object_open_as_commit(&commit, repo, id);
 		if (err)
 			break;
@@ -3833,8 +3837,8 @@ __dead static void
 usage_log(void)
 {
 	fprintf(stderr, "usage: %s log [-b] [-c commit] [-C number] [ -l N ] "
-	    "[-p] [-P] [-x commit] [-s search-pattern] [-r repository-path] "
-	    "[-R] [path]\n", getprogname());
+	    "[-p] [-P] [-x commit] [-X commit] [-s search-pattern] "
+	    "[-r repository-path] [-R] [path]\n", getprogname());
 	exit(1);
 }
 
@@ -3864,7 +3868,7 @@ cmd_log(int argc, char *argv[])
 	char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL;
 	const char *start_commit = NULL, *end_commit = NULL;
 	const char *search_pattern = NULL;
-	int diff_context = -1, ch;
+	int diff_context = -1, ch, traverse_end_commit = 1;
 	int show_changed_paths = 0, show_patch = 0, limit = 0, log_branches = 0;
 	int reverse_display_order = 0;
 	const char *errstr;
@@ -3882,7 +3886,7 @@ cmd_log(int argc, char *argv[])
 
 	limit = get_default_log_limit();
 
-	while ((ch = getopt(argc, argv, "bpPc:C:l:r:Rs:x:")) != -1) {
+	while ((ch = getopt(argc, argv, "bpPc:C:l:r:Rs:x:X:")) != -1) {
 		switch (ch) {
 		case 'p':
 			show_patch = 1;
@@ -3921,8 +3925,18 @@ cmd_log(int argc, char *argv[])
 			search_pattern = optarg;
 			break;
 		case 'x':
+			if (end_commit)
+				err(1, "-x and -X options are mutually "
+				    "exclusive");
 			end_commit = optarg;
 			break;
+		case 'X':
+			if (end_commit)
+				err(1, "-x and -X options are mutually "
+				    "exclusive");
+			end_commit = optarg;
+			traverse_end_commit = 0;
+			break;
 		default:
 			usage_log();
 			/* NOTREACHED */
@@ -4049,7 +4063,8 @@ cmd_log(int argc, char *argv[])
 
 	error = print_commits(start_id, end_id, repo, path ? path : "",
 	    show_changed_paths, show_patch, search_pattern, diff_context,
-	    limit, log_branches, reverse_display_order, refs_idmap);
+	    limit, log_branches, reverse_display_order, traverse_end_commit,
+	    refs_idmap);
 done:
 	free(path);
 	free(repo_path);
@@ -7037,6 +7052,12 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 	if (asprintf(&template, "%s/logmsg", a->worktree_path) == -1)
 		return got_error_from_errno("asprintf");
 
+	initial_content_len = asprintf(&initial_content,
+	    "\n# changes to be committed on branch %s:\n",
+	    a->branch_name);
+	if (initial_content_len == -1)
+		return got_error_from_errno("asprintf");
+
 	err = got_opentemp_named_fd(&a->logmsg_path, &fd, template);
 	if (err)
 		goto done;