[PATCH 2/2] Overly simplistic fix for issue with sha1_file_name() and switching repos

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

 



This is not a final fix, just an illustration of how synchronizing the
"char *base" holding the object directory does in fact fix the test
added by the previous patch. A real fix will explicitly reset "base"
when needed, without comparing with get_object_directory() on every
invocation. A real fix will also have to deal with the other similar
issue in this (and possibly other) file(s).

Signed-off-by: Johan Herland <johan@xxxxxxxxxxx>
---
 sha1_file.c                |    5 +++--
 t/t5700-clone-reference.sh |    2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 4ce4d9d..909226e 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -161,9 +161,10 @@ char *sha1_file_name(const unsigned char *sha1)
 {
 	static char *name, *base;
 
-	if (!base) {
-		const char *sha1_file_directory = get_object_directory();
+	const char *sha1_file_directory = get_object_directory();
+	if (!base || prefixcmp(base, sha1_file_directory) != 0) {
 		int len = strlen(sha1_file_directory);
+		free(base);
 		base = xmalloc(len + 60);
 		memcpy(base, sha1_file_directory, len);
 		memset(base+len, 0, 60);
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 40826ac..0c42d9f 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -134,7 +134,7 @@ git commit -m addition'
 
 cd "$base_dir"
 
-test_expect_failure 'cloning alternate repo #1, using #2 as reference' \
+test_expect_success 'cloning alternate repo #1, using #2 as reference' \
 'git clone --reference G F H'
 
 cd "$base_dir"
-- 
1.5.4.3.328.gcaed

--
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]

  Powered by Linux