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

From:
Josh Rickmar <joshrickmar@outlook.com>
Subject:
Re: Exclusive log end
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Sun, 21 Mar 2021 16:11:34 -0400

Download raw body.

Thread
On Sun, Mar 21, 2021 at 08:31:45PM +0100, Stefan Sperling wrote:
> 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.

Thanks, here's an updated version for others to test.  I made the
variable names a little longer and more descriptive (but
traverse_end_commit -> exclude_end_commit), moved the break up earlier
before the commit object is opened, and used the new
option_conflict().

> I put this aside because I felt it added too much clutter to the UI.
> But if you see a use for this then I am not against adding it.

Fair enough; I'd like to see the UI from becoming incomprehensible as
well.  I actually don't need this (-l1 is usually good enough, and
when it's not, it's probably some other small number that I easily
remember).  I'll let others chime in if they also find it useful or
not.

-----------------------------------------------
commit f4913f6979311a2605ff948f88f02b3411d6f7dc (end_excl)
from: Josh Rickmar <jrick@companyzero.com>
date: Sun Mar 21 20:05:30 2021 UTC
 
 Add log -X (like -x but exclusive)
 
diff 02c0b752d92f95859290b247a9c206b51f6192d9 0311ecc4aa97a21c6fd4c9ef0f79fd793cd50aba
blob - a8b88374d28eb0bf77bcda9f79b0a80b31e5c227
blob + c74f87ab8c3576fa387924952fb03f07382e4a62
--- 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 immediately after 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 immediately before the specified
+.Ar commit
+would 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 - 5a81fddc99d43b6d16f047c9a6ade37e0058f4e6
blob + 24f8e325695e1c5192ec940b064b619298d8438e
--- got/got.c
+++ got/got.c
@@ -3691,13 +3691,13 @@ 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 exclude_end_commit,
     struct got_reflist_object_id_map *refs_idmap)
 {
 	const struct got_error *err;
 	struct got_commit_graph *graph;
 	regex_t regex;
-	int have_match;
+	int have_match, at_end;
 	struct got_object_id_queue reversed_commits;
 	struct got_object_qid *qid;
 	struct got_commit_object *commit;
@@ -3734,6 +3734,10 @@ print_commits(struct got_object_id *root_id, struct go
 		if (id == NULL)
 			break;
 
+		at_end = end_id && got_object_id_cmp(id, end_id) == 0;
+		if (at_end && exclude_end_commit)
+			break;
+
 		err = got_object_open_as_commit(&commit, repo, id);
 		if (err)
 			break;
@@ -3778,8 +3782,7 @@ print_commits(struct got_object_id *root_id, struct go
 			if (err)
 				break;
 		}
-		if ((limit && --limit == 0) ||
-		    (end_id && got_object_id_cmp(id, end_id) == 0))
+		if ((limit && --limit == 0) || at_end)
 			break;
 
 		TAILQ_FOREACH(pe, &changed_paths, entry) {
@@ -3833,8 +3836,9 @@ __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);
 }
 
@@ -3866,7 +3870,7 @@ cmd_log(int argc, char *argv[])
 	const char *search_pattern = NULL;
 	int diff_context = -1, ch;
 	int show_changed_paths = 0, show_patch = 0, limit = 0, log_branches = 0;
-	int reverse_display_order = 0;
+	int reverse_display_order = 0, exclude_end_commit = 0;
 	const char *errstr;
 	struct got_reflist_head refs;
 	struct got_reflist_object_id_map *refs_idmap = NULL;
@@ -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,16 @@ cmd_log(int argc, char *argv[])
 			search_pattern = optarg;
 			break;
 		case 'x':
+			if (end_commit && exclude_end_commit)
+				option_conflict('x', 'X');
 			end_commit = optarg;
 			break;
+		case 'X':
+			if (end_commit && !exclude_end_commit)
+				option_conflict('x', 'X');
+			end_commit = optarg;
+			exclude_end_commit = 1;
+			break;
 		default:
 			usage_log();
 			/* NOTREACHED */
@@ -4049,7 +4061,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, exclude_end_commit,
+	    refs_idmap);
 done:
 	free(path);
 	free(repo_path);