attr: be careful about sparse directories
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Sep 8, 2021 at 01:42 UTC
77efbb366abe53792511580b96a39c636c5b0401
1 file changed
+15
attr.c
+15
@@ -14,6 +14,7 @@
14
#include "utf8.h"
15
#include "quote.h"
16
#include "thread-utils.h"
17
+#include "dir.h"
18
19
const char git_attr__true[] = "(builtin)true";
20
const char git_attr__false[] = "\0(builtin)false";
@@ -744,6 +745,20 @@ static struct attr_stack *read_attr_from_index(struct index_state *istate,
745
if (!istate)
746
return NULL;
747
748
+ /*
749
+ * The .gitattributes file only applies to files within its
750
+ * parent directory. In the case of cone-mode sparse-checkout,
751
+ * the .gitattributes file is sparse if and only if all paths
752
+ * within that directory are also sparse. Thus, don't load the
753
+ * .gitattributes file since it will not matter.
754
+ *
755
+ * In the case of a sparse index, it is critical that we don't go
756
+ * looking for a .gitattributes file, as doing so would cause the
757
+ * index to expand.
758
+ */
759
+ if (!path_in_cone_mode_sparse_checkout(path, istate))
760
+ return NULL;
761
+
762
buf = read_blob_data_from_index(istate, path, NULL);
763
if (!buf)
764
return NULL;