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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: gotwebd: use 'more' for the tags too
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 8 Dec 2023 11:57:07 +0100

Download raw body.

Thread
On Fri, Dec 08, 2023 at 11:11:19AM +0100, Omar Polo wrote:
> this switches the tags listing to the same 'more' button we already use
> in other parts, instead of the next/prev.  Mostly for consistency with
> the rest of the UI.
> 
> ok?

Ok by me, thanks!

> 
> diffstat /home/op/w/got
>  M  gotwebd/got_operations.c  |  23+  54-
>  M  gotwebd/gotweb.c          |  19+  49-
>  M  gotwebd/gotwebd.h         |   2+   3-
>  M  gotwebd/pages.tmpl        |   6+  14-
> 
> 4 files changed, 50 insertions(+), 120 deletions(-)
> 
> diff /home/op/w/got
> commit - f6c7567b8a08e575b7caa23fcea4f93569553835
> path + /home/op/w/got
> blob - 811b305e2a8b1fc494ec5bb3fde95f5c9da249d7
> file + gotwebd/got_operations.c
> --- gotwebd/got_operations.c
> +++ gotwebd/got_operations.c
> @@ -460,11 +460,10 @@ got_get_repo_tags(struct request *c, size_t limit)
>  	struct querystring *qs = t->qs;
>  	struct repo_dir *repo_dir = t->repo_dir;
>  	struct got_tag_object *tag = NULL;
> -	struct repo_tag *rt = NULL, *trt = NULL;
>  	char *in_repo_path = NULL, *repo_path = NULL, *id_str = NULL;
>  	char *tag_commit = NULL, *tag_commit0 = NULL;
>  	char *commit_msg = NULL, *commit_msg0 = NULL;
> -	int chk_next = 0, chk_multi = 1, commit_found = 0, c_cnt = 0;
> +	int chk_next = 0, chk_multi = 1, commit_found = 0;
>  
>  	TAILQ_INIT(&refs);
>  
> @@ -478,28 +477,28 @@ got_get_repo_tags(struct request *c, size_t limit)
>  	if (qs->commit == NULL && (qs->action == TAGS || qs->action == RSS)) {
>  		error = got_ref_open(&ref, repo, qs->headref, 0);
>  		if (error)
> -			goto err;
> +			goto done;
>  		error = got_ref_resolve(&id, repo, ref);
>  		got_ref_close(ref);
>  		if (error)
> -			goto err;
> +			goto done;
>  	} else if (qs->commit == NULL && qs->action == TAG) {
>  		error = got_error_msg(GOT_ERR_EOF, "commit id missing");
> -		goto err;
> +		goto done;
>  	} else {
>  		error = got_repo_match_object_id_prefix(&id, qs->commit,
>  		    GOT_OBJ_TYPE_COMMIT, repo);
>  		if (error)
> -			goto err;
> +			goto done;
>  	}
>  
>  	if (qs->action != SUMMARY && qs->action != TAGS) {
>  		error = got_object_open_as_commit(&commit, repo, id);
>  		if (error)
> -			goto err;
> +			goto done;
>  		error = got_object_commit_get_logmsg(&commit_msg0, commit);
>  		if (error)
> -			goto err;
> +			goto done;
>  		if (commit) {
>  			got_object_commit_close(commit);
>  			commit = NULL;
> @@ -508,12 +507,12 @@ got_get_repo_tags(struct request *c, size_t limit)
>  
>  	error = got_repo_map_path(&in_repo_path, repo, repo_path);
>  	if (error)
> -		goto err;
> +		goto done;
>  
>  	error = got_ref_list(&refs, repo, "refs/tags", got_ref_cmp_tags,
>  	   repo);
>  	if (error)
> -		goto err;
> +		goto done;
>  
>  	if (limit == 1)
>  		chk_multi = 0;
> @@ -526,14 +525,14 @@ got_get_repo_tags(struct request *c, size_t limit)
>  		struct repo_tag *new_repo_tag = NULL;
>  		error = got_init_repo_tag(&new_repo_tag);
>  		if (error)
> -			goto err;
> +			goto done;
>  
>  		TAILQ_INSERT_TAIL(&t->repo_tags, new_repo_tag, entry);
>  
>  		new_repo_tag->tag_name = strdup(got_ref_get_name(re->ref));
>  		if (new_repo_tag->tag_name == NULL) {
>  			error = got_error_from_errno("strdup");
> -			goto err;
> +			goto done;
>  		}
>  
>  		free(id);
> @@ -560,31 +559,31 @@ got_get_repo_tags(struct request *c, size_t limit)
>  			    strdup(got_object_commit_get_committer(commit));
>  			if (new_repo_tag->tagger == NULL) {
>  				error = got_error_from_errno("strdup");
> -				goto err;
> +				goto done;
>  			}
>  			new_repo_tag->tagger_time =
>  			    got_object_commit_get_committer_time(commit);
>  			error = got_object_id_str(&id_str, id);
>  			if (error)
> -				goto err;
> +				goto done;
>  		} else {
>  			new_repo_tag->tagger =
>  			    strdup(got_object_tag_get_tagger(tag));
>  			if (new_repo_tag->tagger == NULL) {
>  				error = got_error_from_errno("strdup");
> -				goto err;
> +				goto done;
>  			}
>  			new_repo_tag->tagger_time =
>  			    got_object_tag_get_tagger_time(tag);
>  			error = got_object_id_str(&id_str,
>  			    got_object_tag_get_object_id(tag));
>  			if (error)
> -				goto err;
> +				goto done;
>  		}
>  
>  		new_repo_tag->commit_id = strdup(id_str);
>  		if (new_repo_tag->commit_id == NULL)
> -			goto err;
> +			goto done;
>  
>  		if (commit_found == 0 && qs->commit != NULL &&
>  		    strncmp(id_str, qs->commit, strlen(id_str)) != 0)
> @@ -600,10 +599,10 @@ got_get_repo_tags(struct request *c, size_t limit)
>  		 * commits and summary
>  		 */
>  		if (chk_next) {
> -			t->next_id = strdup(new_repo_tag->commit_id);
> -			if (t->next_id == NULL) {
> +			t->tags_more_id = strdup(new_repo_tag->commit_id);
> +			if (t->tags_more_id == NULL) {
>  				error = got_error_from_errno("strdup");
> -				goto err;
> +				goto done;
>  			}
>  			if (commit) {
>  				got_object_commit_close(commit);
> @@ -618,14 +617,14 @@ got_get_repo_tags(struct request *c, size_t limit)
>  			error = got_object_commit_get_logmsg(&tag_commit0,
>  			    commit);
>  			if (error)
> -				goto err;
> +				goto done;
>  			got_object_commit_close(commit);
>  			commit = NULL;
>  		} else {
>  			tag_commit0 = strdup(got_object_tag_get_message(tag));
>  			if (tag_commit0 == NULL) {
>  				error = got_error_from_errno("strdup");
> -				goto err;
> +				goto done;
>  			}
>  		}
>  
> @@ -636,7 +635,7 @@ got_get_repo_tags(struct request *c, size_t limit)
>  		if (new_repo_tag->tag_commit == NULL) {
>  			error = got_error_from_errno("strdup");
>  			free(tag_commit0);
> -			goto err;
> +			goto done;
>  		}
>  		free(tag_commit0);
>  
> @@ -648,7 +647,7 @@ got_get_repo_tags(struct request *c, size_t limit)
>  			new_repo_tag->commit_msg = strdup(commit_msg);
>  			if (new_repo_tag->commit_msg == NULL) {
>  				error = got_error_from_errno("strdup");
> -				goto err;
> +				goto done;
>  			}
>  		}
>  
> @@ -660,36 +659,6 @@ got_get_repo_tags(struct request *c, size_t limit)
>  	}
>  
>   done:
> -	/*
> -	 * we have tailq populated, so find previous commit id
> -	 * for navigation through briefs and commits
> -	 */
> -	if (t->tag_count == 0) {
> -		TAILQ_FOREACH_SAFE(rt, &t->repo_tags, entry, trt) {
> -			TAILQ_REMOVE(&t->repo_tags, rt, entry);
> -			gotweb_free_repo_tag(rt);
> -		}
> -	}
> -	if (t->tag_count > 0 && t->prev_id == NULL && qs->commit != NULL) {
> -		commit_found = 0;
> -		TAILQ_FOREACH_REVERSE(rt, &t->repo_tags, repo_tags_head,
> -		    entry) {
> -			if (commit_found == 0 && rt->commit_id != NULL &&
> -			    strcmp(qs->commit, rt->commit_id) != 0) {
> -				continue;
> -			} else
> -				commit_found = 1;
> -			if (c_cnt == srv->max_commits_display ||
> -			    rt == TAILQ_FIRST(&t->repo_tags)) {
> -				t->prev_id = strdup(rt->commit_id);
> -				if (t->prev_id == NULL)
> -					error = got_error_from_errno("strdup");
> -				break;
> -			}
> -			c_cnt++;
> -		}
> -	}
> - err:
>  	if (commit)
>  		got_object_commit_close(commit);
>  	if (tag)
> blob - eb61b43d2ee522780085b404bdef3baabfb6d050
> file + gotwebd/gotweb.c
> --- gotwebd/gotweb.c
> +++ gotwebd/gotweb.c
> @@ -745,8 +745,7 @@ gotweb_free_transport(struct transport *t)
>  	gotweb_free_repo_dir(t->repo_dir);
>  	gotweb_free_querystring(t->qs);
>  	free(t->more_id);
> -	free(t->next_id);
> -	free(t->prev_id);
> +	free(t->tags_more_id);
>  	if (t->blob)
>  		got_object_blob_close(t->blob);
>  	if (t->fp) {
> @@ -768,7 +767,7 @@ gotweb_free_transport(struct transport *t)
>  }
>  
>  void
> -gotweb_get_navs(struct request *c, struct gotweb_url *prev, int *have_prev,
> +gotweb_index_navs(struct request *c, struct gotweb_url *prev, int *have_prev,
>      struct gotweb_url *next, int *have_next)
>  {
>  	struct transport *t = c->t;
> @@ -777,53 +776,24 @@ gotweb_get_navs(struct request *c, struct gotweb_url *
>  
>  	*have_prev = *have_next = 0;
>  
> -	switch(qs->action) {
> -	case INDEX:
> -		if (qs->index_page > 0) {
> -			*have_prev = 1;
> -			*prev = (struct gotweb_url){
> -				.action = -1,
> -				.index_page = qs->index_page - 1,
> -				.page = -1,
> -			};
> -		}
> -		if (t->next_disp == srv->max_repos_display &&
> -		    t->repos_total != (qs->index_page + 1) *
> -		    srv->max_repos_display) {
> -			*have_next = 1;
> -			*next = (struct gotweb_url){
> -				.action = -1,
> -				.index_page = qs->index_page + 1,
> -				.page = -1,
> -			};
> -		}
> -		break;
> -	case TAGS:
> -		if (t->prev_id && qs->commit != NULL &&
> -		    strcmp(qs->commit, t->prev_id) != 0) {
> -			*have_prev = 1;
> -			*prev = (struct gotweb_url){
> -				.action = TAGS,
> -				.index_page = -1,
> -				.page = qs->page - 1,
> -				.path = qs->path,
> -				.commit = t->prev_id,
> -				.headref = qs->headref,
> -			};
> -		}
> -		if (t->next_id) {
> -			*have_next = 1;
> -			*next = (struct gotweb_url){
> -				.action = TAGS,
> -				.index_page = -1,
> -				.page = qs->page + 1,
> -				.path = qs->path,
> -				.commit = t->next_id,
> -				.headref = qs->headref,
> -			};
> -		}
> -		break;
> +	if (qs->index_page > 0) {
> +		*have_prev = 1;
> +		*prev = (struct gotweb_url){
> +			.action = -1,
> +			.index_page = qs->index_page - 1,
> +			.page = -1,
> +		};
>  	}
> +	if (t->next_disp == srv->max_repos_display &&
> +	    t->repos_total != (qs->index_page + 1) *
> +	    srv->max_repos_display) {
> +		*have_next = 1;
> +		*next = (struct gotweb_url){
> +			.action = -1,
> +			.index_page = qs->index_page + 1,
> +			.page = -1,
> +		};
> +	}
>  }
>  
>  static int
> blob - 108a7b3500fd706e64a0b9a2fa6519196ebe51ca
> file + gotwebd/gotwebd.h
> --- gotwebd/gotwebd.h
> +++ gotwebd/gotwebd.h
> @@ -203,8 +203,7 @@ struct transport {
>  	struct repo_dir		*repo_dir;
>  	struct querystring	*qs;
>  	char			*more_id;
> -	char			*next_id;
> -	char			*prev_id;
> +	char			*tags_more_id;
>  	unsigned int		 repos_total;
>  	unsigned int		 next_disp;
>  	unsigned int		 prev_disp;
> @@ -467,7 +466,7 @@ void sockets_socket_accept(int, short, void *);
>  int sockets_privinit(struct gotwebd *, struct socket *);
>  
>  /* gotweb.c */
> -void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
> +void gotweb_index_navs(struct request *, struct gotweb_url *, int *,
>      struct gotweb_url *, int *);
>  int gotweb_render_age(struct template *, time_t);
>  const struct got_error *gotweb_init_transport(struct transport **);
> blob - 885a22e5fd3853508cf60ca2c14474a54087fb75
> file + gotwebd/pages.tmpl
> --- gotwebd/pages.tmpl
> +++ gotwebd/pages.tmpl
> @@ -444,8 +444,11 @@ nextsep(char *s, char **t)
>  		.headref = qs->headref,
>  		.file = qs->file,
>  	};
> +
> +	if (action == TAGS)
> +		more.commit = t->tags_more_id;
>  !}
> -  {{ if t->more_id }}
> +  {{ if more.commit }}
>      <div id="np_wrapper">
>        <div id="nav_more">
>          <a href="{{ render gotweb_render_url(c, &more) }}">
> @@ -459,11 +462,10 @@ nextsep(char *s, char **t)
>  {{ define gotweb_render_navs(struct template *tp) }}
>  {!
>  	struct request		*c = tp->tp_arg;
> -	struct transport	*t = c->t;
>  	struct gotweb_url	 prev, next;
>  	int			 have_prev, have_next;
>  
> -	gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
> +	gotweb_index_navs(c, &prev, &have_prev, &next, &have_next);
>  !}
>  <div id="np_wrapper">
>    <div id="nav_prev">
> @@ -481,13 +483,6 @@ nextsep(char *s, char **t)
>      {{ end }}
>    </div>
>  </div>
> -{{ finally }}
> -{!
> -	free(t->next_id);
> -	t->next_id = NULL;
> -	free(t->prev_id);
> -	t->prev_id = NULL;
> -!}
>  {{ end }}
>  
>  {{ define gotweb_render_commits(struct template *tp) }}
> @@ -824,10 +819,7 @@ nextsep(char *s, char **t)
>          {{ render tag_item(tp, rt) }}
>        {{ end }}
>      {{ end }}
> -    {{ if t->next_id || t->prev_id }}
> -      {! qs->action = TAGS; !}
> -      {{ render gotweb_render_navs(tp) }}
> -    {{ end }}
> +    {{ render gotweb_render_more(tp, TAGS) }}
>    {{ end }}
>  </div>
>  {{ end }}
> 
>