[WIP PATCH 09/26] hash-object: move gitdir setup to run_builtin()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 builtin-hash-object.c |    9 +++++----
 git.c                 |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin-hash-object.c b/builtin-hash-object.c
index 6a5f5b5..57330b8 100644
--- a/builtin-hash-object.c
+++ b/builtin-hash-object.c
@@ -76,7 +76,7 @@ static const struct option hash_object_options[] = {
 int cmd_hash_object(int argc, const char **argv, const char *prefix)
 {
 	int i;
-	int prefix_length = -1;
+	int prefix_length;
 	const char *errstr = NULL;
 
 	type = blob_type;
@@ -84,9 +84,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, NULL, hash_object_options,
 			     hash_object_usage, 0);
 
+	prefix_length = prefix ? strlen(prefix) : 0;
 	if (write_object) {
-		prefix = setup_git_directory();
-		prefix_length = prefix ? strlen(prefix) : 0;
+		if (!startup_info->have_repository)
+			die("No repository found");
 		if (vpath && prefix)
 			vpath = prefix_filename(prefix, prefix_length, vpath);
 	}
@@ -121,7 +122,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
 	for (i = 0 ; i < argc; i++) {
 		const char *arg = argv[i];
 
-		if (0 <= prefix_length)
+		if (prefix_length)
 			arg = prefix_filename(prefix, prefix_length, arg);
 		hash_object(arg, type, write_object,
 			    no_filters ? NULL : vpath ? vpath : arg);
diff --git a/git.c b/git.c
index 0022f02..a165b43 100644
--- a/git.c
+++ b/git.c
@@ -340,7 +340,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "gc", cmd_gc, RUN_SETUP },
 		{ "get-tar-commit-id", cmd_get_tar_commit_id },
 		{ "grep", cmd_grep, USE_PAGER },
-		{ "hash-object", cmd_hash_object },
+		{ "hash-object", cmd_hash_object, RUN_SETUP_GENTLY },
 		{ "help", cmd_help },
 		{ "index-pack", cmd_index_pack },
 		{ "init", cmd_init_db },
-- 
1.7.0.195.g637a2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]