MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / lower

Method lower

atomic-cli/src/commands/git/span_compiler.rs:36–179  ·  view source on GitHub ↗
(
        &self,
        pending: &[PendingLineIndexUpdate],
        hunks: &mut Vec<GraphOp<Option<ContentHash>>>,
    )

Source from the content-addressed store, hash-verified

34
35impl SpanCompiler {
36 pub(super) fn lower(
37 &self,
38 pending: &[PendingLineIndexUpdate],
39 hunks: &mut Vec<GraphOp<Option<ContentHash>>>,
40 ) -> CliResult<(Vec<SpanOp>, Vec<NewRoot>)> {
41 let mut ops = Vec::new();
42 let mut roots = Vec::new();
43 for update in pending {
44 match update {
45 PendingLineIndexUpdate::Add {
46 path, new_ranges, ..
47 } => {
48 let (empty_start, root_path) = hunks
49 .iter()
50 .find_map(|hunk| {
51 if let GraphOp::FileAdd {
52 path: name,
53 add_inode,
54 ..
55 } = hunk
56 {
57 (atomic_repository::canonical_path_identity(name)
58 == atomic_repository::canonical_path_identity(path))
59 .then_some((add_inode.start.get(), name.clone()))
60 } else {
61 None
62 }
63 })
64 .ok_or_else(|| {
65 git_error(format!("span add has no namespace operation for {path}"))
66 })?;
67 let start = new_ranges
68 .first()
69 .map_or(empty_start, |range| range.0.get());
70 let end = new_ranges.last().map_or(start, |range| range.1.get());
71 let ordinal = u32::try_from(roots.len())
72 .map_err(|_| git_error("too many span roots in one change"))?;
73 ops.push(SpanOp::Root {
74 path: root_path,
75 ordinal,
76 start,
77 end,
78 });
79 roots.push(NewRoot {
80 path: path.clone(),
81 ordinal,
82 start,
83 end,
84 });
85 }
86 PendingLineIndexUpdate::Modify { path, replacements } => {
87 let file = self.files.get(path).ok_or_else(|| {
88 git_error(format!("span file identity missing for {path}"))
89 })?;
90 for replacement in replacements {
91 let begin = replacement.start_idx;
92 let end = begin
93 .checked_add(replacement.old_len)

Callers 1

compileMethod · 0.80

Calls 9

canonical_path_identityFunction · 0.85
lastMethod · 0.80
git_errorFunction · 0.70
getMethod · 0.65
clearMethod · 0.65
iterMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected