[PATCH 4/7] sha1_file: refuse to write trees referring to external objects

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

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 sha1_file.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/sha1_file.c b/sha1_file.c
index 5948dcb..ec3a040 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2643,6 +2643,29 @@ static void check_sha1_file_for_external_source(const char *buf,
 				    sha1_to_hex(sha1));
 			buf += 48; /* "parent " + hex sha1 + "\n" */
 		}
+	} else if (!strcmp(type, "tree")) {
+		struct tree_desc desc;
+		struct name_entry entry;
+
+		init_tree_desc(&desc, buf, len);
+		while (tree_entry(&desc, &entry))
+			switch (entry.mode) {
+			case S_IFGITLINK:
+				/* we already know we probably don't have this SHA-1 */
+				break;
+			case S_IFDIR:
+				if (sha1_object_info_extended(entry.sha1, &oi) != OBJ_TREE ||
+				    (oi.alt && oi.alt->external))
+					die("cannot create a tree with external tree %s",
+					    sha1_to_hex(entry.sha1));
+				break;
+			default:
+				if (sha1_object_info_extended(entry.sha1, &oi) != OBJ_BLOB ||
+				    (oi.alt && oi.alt->external))
+					die("cannot create a tree with external blob %s",
+					    sha1_to_hex(entry.sha1));
+				break;
+			}
 	}
 }
 
-- 
1.8.0.rc3.18.g0d9b108

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