git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[WIP PATCH 19/26] apply: move up gitdir setup to run_builtin()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 16, 2010, 16:05 UTC
Message-ID
<1266336317-607-20-git-send-email-pclouds@gmail.com>
In-Reply-To
<1266336317-607-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-apply.c |   13 ++++++-------
 git.c           |    2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 2a1004d..44bb74f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -26,7 +26,7 @@
  *  --cached updates only the cache without ever touching the working tree.
  */
 static const char *prefix;
-static int prefix_length = -1;
+static int prefix_length;
 static int newfd = -1;
 
 static int unidiff_zero;
@@ -2441,7 +2441,7 @@ static int apply_binary(struct image *img, struct patch *patch)
 		return 0; /* deletion patch */
 	}
 
-	if (has_sha1_file(sha1)) {
+	if (startup_info->have_repository && has_sha1_file(sha1)) {
 		/* We already have the postimage */
 		enum object_type type;
 		unsigned long size;
@@ -3512,11 +3512,10 @@ static int option_parse_directory(const struct option *opt,
 	return 0;
 }
 
-int cmd_apply(int argc, const char **argv, const char *unused_prefix)
+int cmd_apply(int argc, const char **argv, const char *prefix_)
 {
 	int i;
 	int errs = 0;
-	int is_not_gitdir;
 	int binary;
 	int force_apply = 0;
 
@@ -3589,7 +3588,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 		OPT_END()
 	};
 
-	prefix = setup_git_directory_gently(&is_not_gitdir);
+	prefix = prefix_;
 	prefix_length = prefix ? strlen(prefix) : 0;
 	git_config(git_apply_config, NULL);
 	if (apply_default_whitespace)
@@ -3604,10 +3603,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 		apply = apply_verbosely = 1;
 	if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))
 		apply = 0;
-	if (check_index && is_not_gitdir)
+	if (check_index && !startup_info->have_repository)
 		die("--index outside a repository");
 	if (cached) {
-		if (is_not_gitdir)
+		if (!startup_info->have_repository)
 			die("--cached outside a repository");
 		check_index = 1;
 	}
diff --git a/git.c b/git.c
index ee596bb..96ccedd 100644
--- a/git.c
+++ b/git.c
@@ -307,7 +307,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "annotate", cmd_annotate, RUN_SETUP },
-		{ "apply", cmd_apply },
+		{ "apply", cmd_apply, RUN_SETUP_GENTLY },
 		{ "archive", cmd_archive, RUN_SETUP_GENTLY },
 		{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
 		{ "blame", cmd_blame, RUN_SETUP },
-- 
1.7.0.195.g637a2
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 20 of 27 in “Git setup cleanup series”
  1. 00/26 Git setup cleanup seriesNguyễn Thái Ngọc Duy, Feb 16, 2010
  2. 01/26 rev-parse --git-dir: print relative gitdir correctlyNguyễn Thái Ngọc Duy, Feb 16, 2010
  3. 02/26 setup_git_directory*: Explicitly set git dirNguyễn Thái Ngọc Duy, Feb 16, 2010
  4. 03/26 Save setup_git_dir* info globally for later useNguyễn Thái Ngọc Duy, Feb 16, 2010
  5. 04/26 Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errorsNguyễn Thái Ngọc Duy, Feb 16, 2010
  6. 05/26 enter_repo(): use setup_git_directory_gently internallyNguyễn Thái Ngọc Duy, Feb 16, 2010
  7. 06/26 Tweak init/clone to work properly with GIT_HARDENED_SETUP=1Nguyễn Thái Ngọc Duy, Feb 16, 2010
  8. 07/26 Support running setup_git_dir_gently() from the beginning for builtin commandsNguyễn Thái Ngọc Duy, Feb 16, 2010
  9. 08/26 config: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  10. 09/26 hash-object: move gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  11. 10/26 shortlog: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  12. 11/26 Do not look for .git/info/exclude when gitdir is not set upNguyễn Thái Ngọc Duy, Feb 16, 2010
  13. 12/26 grep: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  14. 13/26 USE_PAGER should not be used without RUN_SETUP*Nguyễn Thái Ngọc Duy, Feb 16, 2010
  15. 14/26 Do not try to read $GIT_DIR/info/attributes if there is no repositoryNguyễn Thái Ngọc Duy, Feb 16, 2010
  16. 15/26 archive: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  17. 16/26 mailinfo: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  18. 17/26 check-ref-format: setup gitdir gentlyNguyễn Thái Ngọc Duy, Feb 16, 2010
  19. 18/26 verify-pack: set up gitdir gentlyNguyễn Thái Ngọc Duy, Feb 16, 2010
  20. 19/26 apply: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  21. 20/26 bundle: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  22. 21/26 diff: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  23. 22/26 help: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  24. 23/26 ls-remote: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  25. 24/26 var: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  26. 25/26 merge-file: move up gitdir setup to run_builtin()Nguyễn Thái Ngọc Duy, Feb 16, 2010
  27. 26/26 Turn on GIT_HARDENED_SETUP for the whole test suiteNguyễn Thái Ngọc Duy, Feb 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.