History

fix: disallow reading macros when they are not global.

Sebastian Thiel committed 3 years ago

Commit c86ca691 parent c20ec281 file · +26 −8Browse files

Unified · Split

gix-worktree/src/cache/state/attributes.rs+26−8
@@ -92,6 +92,7 @@ impl Attributes { · 91 unmodified lines
9292 let attr_file_in_index = id_mappings.binary_search_by(|t| t.0.as_bstr().cmp(attr_path_relative.as_ref()));
9393 // Git does not follow symbolic links as per documentation.
9494 let no_follow_symlinks = false;
95+ let read_macros_as_dir_is_root = root == dir;
9596
9697 let mut added = false;
9798 match self.source {
@@ -100,8 +101,13 @@ impl Attributes { · 2 unmodified lines
100101 let blob = find(&id_mappings[idx].1, buf)
101102 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
102103 let attr_path = gix_path::from_bstring(attr_path_relative.into_owned());
103− self.stack
104− .add_patterns_buffer(blob.data, attr_path, Some(Path::new("")), &mut self.collection);
104+ self.stack.add_patterns_buffer(
105+ blob.data,
106+ attr_path,
107+ Some(Path::new("")),
108+ &mut self.collection,
109+ read_macros_as_dir_is_root,
110+ );
105111 added = true;
106112 stats.patterns_buffers += 1;
107113 }
@@ -112,6 +118,7 @@ impl Attributes { · 4 unmodified lines
112118 Some(root),
113119 buf,
114120 &mut self.collection,
121+ read_macros_as_dir_is_root,
115122 )?;
116123 stats.pattern_files += usize::from(added);
117124 stats.tried_pattern_files += 1;
@@ -124,6 +131,7 @@ impl Attributes { · 6 unmodified lines
124131 Some(root),
125132 buf,
126133 &mut self.collection,
134+ read_macros_as_dir_is_root,
127135 )?;
128136 stats.pattern_files += usize::from(added);
129137 stats.tried_pattern_files += 1;
@@ -131,8 +139,13 @@ impl Attributes { · 1 unmodified line
131139 let blob = find(&id_mappings[idx].1, buf)
132140 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
133141 let attr_path = gix_path::from_bstring(attr_path_relative.into_owned());
134− self.stack
135− .add_patterns_buffer(blob.data, attr_path, Some(Path::new("")), &mut self.collection);
142+ self.stack.add_patterns_buffer(
143+ blob.data,
144+ attr_path,
145+ Some(Path::new("")),
146+ &mut self.collection,
147+ read_macros_as_dir_is_root,
148+ );
136149 added = true;
137150 stats.patterns_buffers += 1;
138151 }
@@ -142,15 +155,20 @@ impl Attributes { · 3 unmodified lines
142155 // Need one stack level per component so push and pop matches, but only if this isn't the root level which is never popped.
143156 if !added && self.info_attributes.is_none() {
144157 self.stack
145− .add_patterns_buffer(&[], Path::new("<empty dummy>"), None, &mut self.collection)
158+ .add_patterns_buffer(&[], Path::new("<empty dummy>"), None, &mut self.collection, true)
146159 }
147160
148161 // When reading the root, always the first call, we can try to also read the `.git/info/attributes` file which is
149162 // by nature never popped, and follows the root, as global.
150163 if let Some(info_attr) = self.info_attributes.take() {
151− let added = self
152− .stack
153− .add_patterns_file(info_attr, true, None, buf, &mut self.collection)?;
164+ let added = self.stack.add_patterns_file(
165+ info_attr,
166+ true,
167+ None,
168+ buf,
169+ &mut self.collection,
170+ true, /* read macros */
171+ )?;
154172 stats.pattern_files += usize::from(added);
155173 stats.tried_pattern_files += 1;
156174 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t