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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: Fix "tog diff obj1 obj2"
To:
Christian Weisgerber <naddy@mips.inka.de>
Cc:
gameoftrees@openbsd.org
Date:
Sun, 23 Feb 2020 12:19:49 +0100

Download raw body.

Thread
  • Christian Weisgerber:

    Fix "tog diff obj1 obj2"

    • Stefan Sperling:

      Fix "tog diff obj1 obj2"

On Sun, Feb 23, 2020 at 12:12:37AM +0100, Christian Weisgerber wrote:
> tog.1 promises that you can do "tog diff obj1 obj2" in a work tree, but
> this isn't implemented correctly.
> 
>  fix "tog diff object1 object2" by actually extracting the repository path
>  from the work tree

OK. I have reproduced the issue and your fix works.  Thank you!

> diff 575cb0c1ffb9850755d9eb82aeb58456c162bf2b 28e8fe3acba2cedafee5e122442ff2a68f84bc45
> blob - cedb43dd64ce5c18d0d3451f7b9f8d0e922264b2
> blob + 1a25cb86d8ee8854fc60c819572513bd7d475850
> --- tog/tog.c
> +++ tog/tog.c
> @@ -3475,9 +3475,10 @@ cmd_diff(int argc, char *argv[])
>  {
>  	const struct got_error *error = NULL;
>  	struct got_repository *repo = NULL;
> +	struct got_worktree *worktree = NULL;
>  	struct got_reflist_head refs;
>  	struct got_object_id *id1 = NULL, *id2 = NULL;
> -	char *repo_path = NULL;
> +	char *repo_path = NULL, *cwd = NULL;
>  	char *id_str1 = NULL, *id_str2 = NULL;
>  	int ch;
>  	struct tog_view *view;
> @@ -3504,9 +3505,6 @@ cmd_diff(int argc, char *argv[])
>  	if (argc == 0) {
>  		usage_diff(); /* TODO show local worktree changes */
>  	} else if (argc == 2) {
> -		repo_path = getcwd(NULL, 0);
> -		if (repo_path == NULL)
> -			return got_error_from_errno("getcwd");
>  		id_str1 = argv[0];
>  		id_str2 = argv[1];
>  	} else if (argc == 3) {
> @@ -3518,12 +3516,32 @@ cmd_diff(int argc, char *argv[])
>  	} else
>  		usage_diff();
>  
> -	init_curses();
> +	cwd = getcwd(NULL, 0);
> +	if (cwd == NULL)
> +		return got_error_from_errno("getcwd");
>  
> +	error = got_worktree_open(&worktree, cwd);
> +	if (error && error->code != GOT_ERR_NOT_WORKTREE)
> +		goto done;
> +
> +	if (repo_path == NULL) {
> +		if (worktree)
> +			repo_path =
> +			    strdup(got_worktree_get_repo_path(worktree));
> +		else
> +			repo_path = strdup(cwd);
> +	}
> +	if (repo_path == NULL) {
> +		error = got_error_from_errno("strdup");
> +		goto done;
> +	}
> +
>  	error = got_repo_open(&repo, repo_path, NULL);
>  	if (error)
>  		goto done;
>  
> +	init_curses();
> +
>  	error = apply_unveil(got_repo_get_path(repo), NULL);
>  	if (error)
>  		goto done;
> @@ -3553,8 +3571,11 @@ cmd_diff(int argc, char *argv[])
>  	error = view_loop(view);
>  done:
>  	free(repo_path);
> +	free(cwd);
>  	if (repo)
>  		got_repo_close(repo);
> +	if (worktree)
> +		got_worktree_close(worktree);
>  	got_ref_list_free(&refs);
>  	return error;
>  }
> 
> -- 
> Christian "naddy" Weisgerber                          naddy@mips.inka.de
> 
>