path: stop relying on `the_repository` in `worktree_git_path()`
When not provided a worktree, then `worktree_git_path()` will fall back to returning a path relative to the main repository. In this case, we implicitly rely on `the_repository` to derive the path. Remove this dependency by passing a `struct repository` as parameter. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									78f2210b3c
								
							
						
					
					
						commit
						a973f60dc7
					
				|  | @ -1050,7 +1050,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) | ||||||
| 			 * and may get overwritten by other calls | 			 * and may get overwritten by other calls | ||||||
| 			 * while we're examining the index. | 			 * while we're examining the index. | ||||||
| 			 */ | 			 */ | ||||||
| 			path = xstrdup(worktree_git_path(wt, "index")); | 			path = xstrdup(worktree_git_path(the_repository, wt, "index")); | ||||||
| 			read_index_from(&istate, path, get_worktree_git_dir(wt)); | 			read_index_from(&istate, path, get_worktree_git_dir(wt)); | ||||||
| 			fsck_index(&istate, path, wt->is_current); | 			fsck_index(&istate, path, wt->is_current); | ||||||
| 			discard_index(&istate); | 			discard_index(&istate); | ||||||
|  |  | ||||||
|  | @ -1146,14 +1146,14 @@ static void validate_no_submodules(const struct worktree *wt) | ||||||
| 	struct strbuf path = STRBUF_INIT; | 	struct strbuf path = STRBUF_INIT; | ||||||
| 	int i, found_submodules = 0; | 	int i, found_submodules = 0; | ||||||
|  |  | ||||||
| 	if (is_directory(worktree_git_path(wt, "modules"))) { | 	if (is_directory(worktree_git_path(the_repository, wt, "modules"))) { | ||||||
| 		/* | 		/* | ||||||
| 		 * There could be false positives, e.g. the "modules" | 		 * There could be false positives, e.g. the "modules" | ||||||
| 		 * directory exists but is empty. But it's a rare case and | 		 * directory exists but is empty. But it's a rare case and | ||||||
| 		 * this simpler check is probably good enough for now. | 		 * this simpler check is probably good enough for now. | ||||||
| 		 */ | 		 */ | ||||||
| 		found_submodules = 1; | 		found_submodules = 1; | ||||||
| 	} else if (read_index_from(&istate, worktree_git_path(wt, "index"), | 	} else if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"), | ||||||
| 				   get_worktree_git_dir(wt)) > 0) { | 				   get_worktree_git_dir(wt)) > 0) { | ||||||
| 		for (i = 0; i < istate.cache_nr; i++) { | 		for (i = 0; i < istate.cache_nr; i++) { | ||||||
| 			struct cache_entry *ce = istate.cache[i]; | 			struct cache_entry *ce = istate.cache[i]; | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								path.c
								
								
								
								
							
							
						
						
									
										9
									
								
								path.c
								
								
								
								
							|  | @ -512,12 +512,17 @@ const char *mkpath(const char *fmt, ...) | ||||||
| 	return cleanup_path(pathname->buf); | 	return cleanup_path(pathname->buf); | ||||||
| } | } | ||||||
|  |  | ||||||
| const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...) | const char *worktree_git_path(struct repository *r, | ||||||
|  | 			      const struct worktree *wt, const char *fmt, ...) | ||||||
| { | { | ||||||
| 	struct strbuf *pathname = get_pathname(); | 	struct strbuf *pathname = get_pathname(); | ||||||
| 	va_list args; | 	va_list args; | ||||||
|  |  | ||||||
|  | 	if (wt && wt->repo != r) | ||||||
|  | 		BUG("worktree not connected to expected repository"); | ||||||
|  |  | ||||||
| 	va_start(args, fmt); | 	va_start(args, fmt); | ||||||
| 	repo_git_pathv(the_repository, wt, pathname, fmt, args); | 	repo_git_pathv(r, wt, pathname, fmt, args); | ||||||
| 	va_end(args); | 	va_end(args); | ||||||
| 	return pathname->buf; | 	return pathname->buf; | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										8
									
								
								path.h
								
								
								
								
							
							
						
						
									
										8
									
								
								path.h
								
								
								
								
							|  | @ -95,11 +95,13 @@ const char *git_path(const char *fmt, ...) | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Similar to git_path() but can produce paths for a specified |  * Similar to git_path() but can produce paths for a specified | ||||||
|  * worktree instead of current one |  * worktree instead of current one. When no worktree is given, then the path is | ||||||
|  |  * computed relative to main worktree of the given repository. | ||||||
|  */ |  */ | ||||||
| const char *worktree_git_path(const struct worktree *wt, | const char *worktree_git_path(struct repository *r, | ||||||
|  | 			      const struct worktree *wt, | ||||||
| 			      const char *fmt, ...) | 			      const char *fmt, ...) | ||||||
| 	__attribute__((format (printf, 2, 3))); | 	__attribute__((format (printf, 3, 4))); | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Return a path into the main repository's (the_repository) git directory. |  * Return a path into the main repository's (the_repository) git directory. | ||||||
|  |  | ||||||
|  | @ -1872,7 +1872,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) | ||||||
| 			continue; /* current index already taken care of */ | 			continue; /* current index already taken care of */ | ||||||
|  |  | ||||||
| 		if (read_index_from(&istate, | 		if (read_index_from(&istate, | ||||||
| 				    worktree_git_path(wt, "index"), | 				    worktree_git_path(the_repository, wt, "index"), | ||||||
| 				    get_worktree_git_dir(wt)) > 0) | 				    get_worktree_git_dir(wt)) > 0) | ||||||
| 			do_add_index_objects_to_pending(revs, &istate, flags); | 			do_add_index_objects_to_pending(revs, &istate, flags); | ||||||
| 		discard_index(&istate); | 		discard_index(&istate); | ||||||
|  |  | ||||||
|  | @ -252,7 +252,7 @@ const char *worktree_lock_reason(struct worktree *wt) | ||||||
| 	if (!wt->lock_reason_valid) { | 	if (!wt->lock_reason_valid) { | ||||||
| 		struct strbuf path = STRBUF_INIT; | 		struct strbuf path = STRBUF_INIT; | ||||||
|  |  | ||||||
| 		strbuf_addstr(&path, worktree_git_path(wt, "locked")); | 		strbuf_addstr(&path, worktree_git_path(the_repository, wt, "locked")); | ||||||
| 		if (file_exists(path.buf)) { | 		if (file_exists(path.buf)) { | ||||||
| 			struct strbuf lock_reason = STRBUF_INIT; | 			struct strbuf lock_reason = STRBUF_INIT; | ||||||
| 			if (strbuf_read_file(&lock_reason, path.buf, 0) < 0) | 			if (strbuf_read_file(&lock_reason, path.buf, 0) < 0) | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								wt-status.c
								
								
								
								
							
							
						
						
									
										14
									
								
								wt-status.c
								
								
								
								
							|  | @ -1618,7 +1618,7 @@ static char *get_branch(const struct worktree *wt, const char *path) | ||||||
| 	struct object_id oid; | 	struct object_id oid; | ||||||
| 	const char *branch_name; | 	const char *branch_name; | ||||||
|  |  | ||||||
| 	if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0) | 	if (strbuf_read_file(&sb, worktree_git_path(the_repository, wt, "%s", path), 0) <= 0) | ||||||
| 		goto got_nothing; | 		goto got_nothing; | ||||||
|  |  | ||||||
| 	while (sb.len && sb.buf[sb.len - 1] == '\n') | 	while (sb.len && sb.buf[sb.len - 1] == '\n') | ||||||
|  | @ -1716,18 +1716,18 @@ int wt_status_check_rebase(const struct worktree *wt, | ||||||
| { | { | ||||||
| 	struct stat st; | 	struct stat st; | ||||||
|  |  | ||||||
| 	if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) { | 	if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) { | ||||||
| 		if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) { | 		if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) { | ||||||
| 			state->am_in_progress = 1; | 			state->am_in_progress = 1; | ||||||
| 			if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size) | 			if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size) | ||||||
| 				state->am_empty_patch = 1; | 				state->am_empty_patch = 1; | ||||||
| 		} else { | 		} else { | ||||||
| 			state->rebase_in_progress = 1; | 			state->rebase_in_progress = 1; | ||||||
| 			state->branch = get_branch(wt, "rebase-apply/head-name"); | 			state->branch = get_branch(wt, "rebase-apply/head-name"); | ||||||
| 			state->onto = get_branch(wt, "rebase-apply/onto"); | 			state->onto = get_branch(wt, "rebase-apply/onto"); | ||||||
| 		} | 		} | ||||||
| 	} else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) { | 	} else if (!stat(worktree_git_path(the_repository, wt, "rebase-merge"), &st)) { | ||||||
| 		if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st)) | 		if (!stat(worktree_git_path(the_repository, wt, "rebase-merge/interactive"), &st)) | ||||||
| 			state->rebase_interactive_in_progress = 1; | 			state->rebase_interactive_in_progress = 1; | ||||||
| 		else | 		else | ||||||
| 			state->rebase_in_progress = 1; | 			state->rebase_in_progress = 1; | ||||||
|  | @ -1743,7 +1743,7 @@ int wt_status_check_bisect(const struct worktree *wt, | ||||||
| { | { | ||||||
| 	struct stat st; | 	struct stat st; | ||||||
|  |  | ||||||
| 	if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) { | 	if (!stat(worktree_git_path(the_repository, wt, "BISECT_LOG"), &st)) { | ||||||
| 		state->bisect_in_progress = 1; | 		state->bisect_in_progress = 1; | ||||||
| 		state->bisecting_from = get_branch(wt, "BISECT_START"); | 		state->bisecting_from = get_branch(wt, "BISECT_START"); | ||||||
| 		return 1; | 		return 1; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Patrick Steinhardt
						Patrick Steinhardt