Skip to contentSkip to conversation

Cleanup sha1_file_directory initialization

PATCH New Jonas Fonseca 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleanup sha1_file_directory initialization

Use get_object_directory() when initializing sha1_file_directory and make sha1_file_name() work on the global.

---
Actually the initiailzation in ls-tree.c can be removed because call to list() will end up in sha1_file_name() which will do it.

commit 6a06750a72231eaf285f9fbd2bcb88a39b699679
tree bec1c4178131a67de1fa639a274b13adec21c1e5
parent 32141512fff2d42c0233c07610db866926c89a75 author Jonas Fonseca <jonas@cvalda.(none)> 1114346881 +0200 committer Jonas Fonseca <jonas@cvalda.(none)> 1114346881 +0200

ls-tree.c (mode:100644 sha1:b630f69d8430f18f52799cf32787059b4427f3e8) renamed from ls-tree.c (mode:100644 sha1:bd99f9ac7b2d6dc23c1ec7d8f03877c20afec63f) +2 -3
Index: ls-tree.c
===================================================================
@@ -104,9 +104,8 @@ int main(int argc, char **argv)
 		usage(ls_tree_usage);
 	if (get_sha1_hex(argv[1], sha1) < 0)
 		usage(ls_tree_usage);
-	sha1_file_directory = getenv(DB_ENVIRONMENT);
-	if (!sha1_file_directory)
-		sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
+
+	sha1_file_directory = get_object_directory();
 	if (list(sha1) < 0)
 		die("list failed");
 	return 0;
read-cache.c (mode:100644 sha1:deb60df8cbb4f9ec8367f4ff96c62e383b5699e8) renamed from read-cache.c (mode:100644 sha1:f67aceb6b12f6d9cadf6a80bb1d33cf1bcd7f619) +1 -3
Index: read-cache.c
===================================================================
@@ -183,9 +183,7 @@ int read_cache(void)
 	if (active_cache)
 		return error("more than one cachefile");
 	errno = ENOENT;
-	sha1_file_directory = getenv(DB_ENVIRONMENT);
-	if (!sha1_file_directory)
-		sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
+	sha1_file_directory = get_object_directory();
 	if (access(sha1_file_directory, X_OK) < 0)
 		return error("no access to SHA1 file directory");
 	fd = open(get_index_file(), O_RDONLY);
sha1_file.c (mode:100644 sha1:94ab1119383a00a821254c3454fe349845027346) renamed from sha1_file.c (mode:100644 sha1:97a515a073fec5870dfaaa279868ce9330853d3d) +5 -2
Index: sha1_file.c
===================================================================
@@ -71,8 +71,11 @@ char *sha1_file_name(const unsigned char
 	static char *name, *base;
 
 	if (!base) {
-		char *sha1_file_directory = getenv(DB_ENVIRONMENT) ? : DEFAULT_DB_ENVIRONMENT;
-		int len = strlen(sha1_file_directory);
+		int len;
+
+		if (!sha1_file_directory)
+			sha1_file_directory = get_object_directory();
+		len = strlen(sha1_file_directory);
 		base = malloc(len + 60);
 		memcpy(base, sha1_file_directory, len);
 		memset(base+len, 0, 60);
Signature · 1 line
Jonas Fonseca