Skip to content

Commit 048e8df

Browse files
authored
Merge pull request #2555 from GitoxideLabs/index-docs
improve gix-index docs
2 parents af9c03d + afa6457 commit 048e8df

5 files changed

Lines changed: 65 additions & 8 deletions

File tree

COLLABORATING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
- …and you _do know_ the cause, please fix it immediately. If necessary by reverting the offending commit until a more durable fix is possible.
1717
- …and you _do not know_ the cause, please open a PR to invite collaborators for their input. This is to avoid multiple collaborators
1818
trying to fix the issue independently, causing merge-conflicts and confusion. We use this PR as synchronization primitive.
19+
- **please disclose AI assistance when collaborating**
20+
- if AI edits files for you, disclose it in the PR description and commit metadata, preferably with an AI author
21+
such as `$agent $version <ai-agent@example.invalid>` or a `Co-authored-by: <agent-identity>` trailer.
22+
- agents operating through a person's GitHub account must identify themselves in comments, for example with phrases
23+
like `AI agent on behalf of <person>: ...`.
24+
- fully AI-generated PR or issue comments must be disclosed. Undisclosed AI-generated comments may lead to the PR or
25+
issue being closed.
26+
- AI-assisted proofreading or wording polish does not need disclosure, but it is still courteous to mention it when
27+
the AI materially influenced the final text.
1928
- **for crates _you own_**
2029
- feel free to make any kind of changes to it, including major ones.
2130
- please use `cargo smart-release` for publishing to crates.io as it will handle dependencies properly.

CONTRIBUTING.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
### Please disclose the use AI…
1+
### Please disclose the use of AI
22

3-
…if it's editing files for you please let us know in the PR comment _or preferably_ using
4-
`Co-authored-by: <agent-identity>` message trailers.
3+
If AI edits files for you, disclose it in the PR description and commit metadata. Prefer making the
4+
agent identity part of the commit, for example by using an AI *author* such as `$agent $version <ai-agent@example.invalid>`
5+
or a *co-author* via `Co-authored-by: <agent-identity>` trailer.
6+
Recent commits in this repository use that pattern, often with a *human* `Co-authored-by` trailer when a person also contributed directly.
7+
8+
Agents operating through a person's GitHub account must identify themselves. For example, comments
9+
posted by an agent should say so directly with phrases like `AI agent on behalf of <person>: ...`.
10+
11+
Fully AI-generated comments on PRs or issues must also be disclosed. Undisclosed AI-generated
12+
comments may lead to the PR or issue being closed.
13+
14+
AI-assisted proofreading or wording polish does not need disclosure, but it is still courteous to
15+
mention it when the AI materially influenced the final text.
516

617
For everything else, please have a look at the respective section in the [README] file.
718

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ We recommend running `just test` during the development process to assure CI is
348348
A backlog for work ready to be picked up is [available in the Project's Kanban board][project-board], which contains instructions on how
349349
to pick a task. If it's empty or you have other questions, feel free to [start a discussion][discussions] or reach out to @Byron [privately][keybase].
350350

351-
For additional details, also take a look at the [collaboration guide].
351+
For additional details, also take a look at the [collaboration guide]. If AI participates in a contribution, please
352+
follow the [AI disclosure requirements]. "Full-auto" contributions without a human on the other end may be closed unceremoniously.
352353

354+
[AI disclosure requirements]: https://github.com/GitoxideLabs/gitoxide/blob/main/CONTRIBUTING.md#please-disclose-the-use-of-ai
353355
[collaboration guide]: https://github.com/GitoxideLabs/gitoxide/blob/main/COLLABORATING.md
354356
[project-board]: https://github.com/GitoxideLabs/gitoxide/projects
355357
[discussions]: https://github.com/GitoxideLabs/gitoxide/discussions

gix-index/src/access/mod.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ impl State {
6969
})
7070
}
7171

72-
/// Find the entry index in [`entries()`][State::entries()] matching the given repository-relative
73-
/// `path` and `stage`, or `None`.
72+
/// Find the entry index in [`entries()`][State::entries()] matching the given `path` and `stage`, or `None`.
73+
///
74+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
7475
///
7576
/// Use the index for accessing multiple stages if they exists, but at least the single matching entry.
7677
pub fn entry_index_by_path_and_stage(&self, path: &BStr, stage: entry::Stage) -> Option<usize> {
@@ -194,6 +195,8 @@ impl State {
194195
/// Return the entry at `path` that is at the lowest available stage, using `lookup` for acceleration.
195196
/// It must have been created from this instance, and was ideally kept up-to-date with it.
196197
///
198+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
199+
///
197200
/// If `ignore_case` is `true`, a case-insensitive (ASCII-folding only) search will be performed.
198201
pub fn entry_by_path_icase<'a>(
199202
&'a self,
@@ -219,6 +222,8 @@ impl State {
219222
/// Return the entry (at any stage) that is inside `directory`, or `None`,
220223
/// or a directory itself like a submodule or sparse directory, using `lookup` for acceleration.
221224
///
225+
/// The `directory` must use the repository-relative, slash-separated [`State`] path format.
226+
///
222227
/// If `ignore_case` is set, a case-insensitive (ASCII-folding only) search will be performed.
223228
pub fn entry_closest_to_directory_or_directory_icase<'a>(
224229
&'a self,
@@ -244,6 +249,8 @@ impl State {
244249
/// Return the entry (at any stage) that is inside `directory`, or `None`,
245250
/// or that is a directory itself like a submodule or sparse directory.
246251
///
252+
/// The `directory` must use the repository-relative, slash-separated [`State`] path format.
253+
///
247254
/// Note that this is a *case-sensitive* search.
248255
pub fn entry_closest_to_directory_or_directory(&self, directory: &BStr) -> Option<&Entry> {
249256
let idx = match self.entry_index_by_path(directory) {
@@ -272,6 +279,8 @@ impl State {
272279

273280
/// Check if `path` is a directory that contains entries in the index, or is a submodule.
274281
///
282+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
283+
///
275284
/// Returns `true` if there is at least one entry in the index whose path starts with `path/`,
276285
/// indicating that `path` is a directory containing indexed files.
277286
///
@@ -286,6 +295,8 @@ impl State {
286295
/// Check if `path` is a directory that contains entries in the index or is a submodule,
287296
/// with optional case-insensitive matching.
288297
///
298+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
299+
///
289300
/// Returns `true` if there is at least one entry in the index whose path starts with `path/`,
290301
/// indicating that `path` is a directory containing indexed files.
291302
///
@@ -304,8 +315,10 @@ impl State {
304315
.is_some()
305316
}
306317

307-
/// Find the entry index in [`entries()[..upper_bound]`][State::entries()] matching the given repository-relative
308-
/// `path` and `stage`, or `None`.
318+
/// Find the entry index in [`entries()[..upper_bound]`][State::entries()] matching the given `path` and `stage`,
319+
/// or `None`.
320+
///
321+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
309322
///
310323
/// Use the index for accessing multiple stages if they exists, but at least the single matching entry.
311324
///
@@ -325,13 +338,17 @@ impl State {
325338

326339
/// Like [`entry_index_by_path_and_stage()`](State::entry_index_by_path_and_stage()),
327340
/// but returns the entry instead of the index.
341+
///
342+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
328343
pub fn entry_by_path_and_stage(&self, path: &BStr, stage: entry::Stage) -> Option<&Entry> {
329344
self.entry_index_by_path_and_stage(path, stage)
330345
.map(|idx| &self.entries[idx])
331346
}
332347

333348
/// Return the entry at `path` that is either at stage 0, or at stage 2 (ours) in case of a merge conflict.
334349
///
350+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
351+
///
335352
/// Using this method is more efficient in comparison to doing two searches, one for stage 0 and one for stage 2.
336353
pub fn entry_by_path(&self, path: &BStr) -> Option<&Entry> {
337354
let mut stage_at_index = 0;
@@ -355,19 +372,25 @@ impl State {
355372

356373
/// Return the index at `Ok(index)` where the entry matching `path` (in any stage) can be found, or return
357374
/// `Err(index)` to indicate the insertion position at which an entry with `path` would fit in.
375+
///
376+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
358377
pub fn entry_index_by_path(&self, path: &BStr) -> Result<usize, usize> {
359378
self.entries.binary_search_by(|e| e.path(self).cmp(path))
360379
}
361380

362381
/// Return the slice of entries which all share the same `prefix`, or `None` if there isn't a single such entry.
363382
///
383+
/// The `prefix` must use the repository-relative, slash-separated [`State`] path format.
384+
///
364385
/// If `prefix` is empty, all entries are returned.
365386
pub fn prefixed_entries(&self, prefix: &BStr) -> Option<&[Entry]> {
366387
self.prefixed_entries_range(prefix).map(|range| &self.entries[range])
367388
}
368389

369390
/// Return the range of entries which all share the same `prefix`, or `None` if there isn't a single such entry.
370391
///
392+
/// The `prefix` must use the repository-relative, slash-separated [`State`] path format.
393+
///
371394
/// If `prefix` is empty, the range will include all entries.
372395
pub fn prefixed_entries_range(&self, prefix: &BStr) -> Option<Range<usize>> {
373396
if prefix.is_empty() {
@@ -415,6 +438,8 @@ impl State {
415438
/// Return the range of entries that exactly match the given `path`, in all available stages, or `None` if no entry with such
416439
/// path exists.
417440
///
441+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
442+
///
418443
/// The range can be used to access the respective entries via [`entries()`](Self::entries()) or [`entries_mut()](Self::entries_mut()).
419444
pub fn entry_range(&self, path: &BStr) -> Option<Range<usize>> {
420445
let mut stage_at_index = 0;
@@ -506,6 +531,8 @@ impl State {
506531

507532
/// Like [`entry_index_by_path_and_stage()`][State::entry_index_by_path_and_stage()],
508533
/// but returns the mutable entry instead of the index.
534+
///
535+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
509536
pub fn entry_mut_by_path_and_stage(&mut self, path: &BStr, stage: entry::Stage) -> Option<&mut Entry> {
510537
self.entry_index_by_path_and_stage(path, stage)
511538
.map(|idx| &mut self.entries[idx])
@@ -515,6 +542,8 @@ impl State {
515542
/// any sanity checks. This means it's possible to push a new entry to the same path on the same stage and even after sorting
516543
/// the entries lookups may still return the wrong one of them unless the correct binary search criteria is chosen.
517544
///
545+
/// The `path` must use the repository-relative, slash-separated [`State`] path format.
546+
///
518547
/// Note that this *is likely* to break invariants that will prevent further lookups by path unless
519548
/// [`entry_index_by_path_and_stage_bounded()`][State::entry_index_by_path_and_stage_bounded()] is used with
520549
/// the `upper_bound` being the amount of entries before the first call to this method.

gix-index/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ pub struct AccelerateLookup<'a> {
112112
/// As opposed to a snapshot, it's meant to be altered and eventually be written back to disk or converted into a tree.
113113
/// We treat index and its state synonymous.
114114
///
115+
/// # Path Format
116+
///
117+
/// All entry paths stored by [`State`], and all path-like arguments used to access entries, are repository-relative byte
118+
/// strings with `/` as separator. They are not platform-native filesystem paths, must not be absolute, and must not use
119+
/// separators like `\`; convert worktree or absolute paths to this representation before lookup or insertion.
120+
///
115121
/// # A note on safety
116122
///
117123
/// An index (i.e. [`State`]) created by hand is not guaranteed to have valid entry paths as they are entirely controlled

0 commit comments

Comments
 (0)