Commit def390d
builtin/repack.c: avoid dir traversal in
When repacking, the function `collect_pack_filenames()` is responsible
for collecting the set of existing packs in the repository, and
partitioning them into "kept" (if the pack has a ".keep" file or was
given via `--keep-pack`) and "nonkept" (otherwise) lists.
This function comes from the original C port of git-repack.sh from back
in a1bbc6c (repack: rewrite the shell script in C, 2013-09-15),
where it first appears as `get_non_kept_pack_filenames()`. At the time,
the implementation was a fairly direct translation from the relevant
portion of git-repack.sh, which looped over the results of
find "$PACKDIR" -type f -name '*.pack'
either ignoring the pack as kept, or adding it to the list of existing
packs.
So the choice to directly translate this function in terms of
`readdir()` in a1bbc6c made sense. At the time, it was possible to
refine the C version in terms of packed_git structs, but was never done.
However, manually enumerating a repository's packs via `readdir()` is
confusing and error-prone. It leads to frustrating inconsistencies
between which packs Git considers to be part of a repository (i.e.,
could be found in the list of packs from `get_all_packs()`), and which
packs `collect_pack_filenames()` considers to meet the same criteria.
This bit us in 73320e4 (builtin/repack.c: only collect fully-formed
packs, 2023-06-07), and again in the previous commit.
Prevent these issues from biting us in the future by implementing the
`collect_pack_filenames()` function by looping over an array of pointers
to `packed_git` structs, ensuring that we use the same criteria to
determine the set of available packs.
One gotcha here is that we have to ignore non-local packs, since the
original version of `collect_pack_filenames()` only looks at the local
pack directory to collect existing packs.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>collect_pack_filenames()
1 parent 0af0672 commit def390d
1 file changed
+15
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
| 109 | + | |
112 | 110 | | |
113 | 111 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 112 | + | |
119 | 113 | | |
| 114 | + | |
120 | 115 | | |
121 | | - | |
| 116 | + | |
122 | 117 | | |
123 | 118 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 119 | + | |
130 | 120 | | |
131 | 121 | | |
132 | | - | |
| 122 | + | |
133 | 123 | | |
134 | 124 | | |
135 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
136 | 128 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
141 | 132 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 133 | + | |
| 134 | + | |
145 | 135 | | |
146 | 136 | | |
147 | 137 | | |
148 | | - | |
149 | | - | |
150 | 138 | | |
151 | 139 | | |
| 140 | + | |
152 | 141 | | |
153 | 142 | | |
154 | 143 | | |
| |||
0 commit comments