(git: &GitRepository)
| 895 | #[cfg(feature = "experimental-span-import")] |
| 896 | impl SpanIncrementalGitObservation { |
| 897 | fn capture(git: &GitRepository) -> CliResult<Self> { |
| 898 | // libgit2's repository index and a Git process using GIT_INDEX_FILE |
| 899 | // need not observe the same index. Until the override is explicitly |
| 900 | // supported, do not claim a clean checkout based on the wrong file. |
| 901 | if std::env::var_os("GIT_INDEX_FILE").is_some() { |
| 902 | return Err(CliError::GitError { |
| 903 | message: |
| 904 | "span incremental import does not support GIT_INDEX_FILE; no import was started" |
| 905 | .into(), |
| 906 | }); |
| 907 | } |
| 908 | if git.state() != git2::RepositoryState::Clean { |
| 909 | return Err(CliError::GitError { |
| 910 | message: "Git has an in-progress operation; span incremental import was refused" |
| 911 | .into(), |
| 912 | }); |
| 913 | } |
| 914 | if git.path().join("index.lock").exists() { |
| 915 | return Err(CliError::GitError { |
| 916 | message: "Git index is locked; span incremental import was refused".into(), |
| 917 | }); |
| 918 | } |
| 919 | let head = git.head().map_err(|error| CliError::GitError { |
| 920 | message: format!("cannot observe Git HEAD: {error}"), |
| 921 | })?; |
| 922 | if !head.is_branch() { |
| 923 | return Err(CliError::GitError { |
| 924 | message: "span incremental import requires an attached Git branch".into(), |
| 925 | }); |
| 926 | } |
| 927 | let branch = head |
| 928 | .shorthand() |
| 929 | .ok() |
| 930 | .ok_or_else(|| CliError::GitError { |
| 931 | message: "Git branch name is not representable".into(), |
| 932 | })? |
| 933 | .to_string(); |
| 934 | let tip = head.target().ok_or_else(|| CliError::GitError { |
| 935 | message: "Git branch has no commit".into(), |
| 936 | })?; |
| 937 | let index = |
| 938 | std::fs::read(git.path().join("index")).map_err(|error| CliError::GitError { |
| 939 | message: format!("cannot inspect Git index: {error}"), |
| 940 | })?; |
| 941 | let mut parsed_index = git.index().map_err(|error| CliError::GitError { |
| 942 | message: format!("cannot inspect Git index entries: {error}"), |
| 943 | })?; |
| 944 | parsed_index |
| 945 | .read(true) |
| 946 | .map_err(|error| CliError::GitError { |
| 947 | message: format!("cannot refresh Git index observation: {error}"), |
| 948 | })?; |
| 949 | if parsed_index.iter().any(|entry| { |
| 950 | // These flags tell Git status not to compare a tracked file with |
| 951 | // the worktree, so clean status cannot establish its bytes. |
| 952 | entry.flags & 0x8000 != 0 || entry.flags_extended & 0x4000 != 0 |
| 953 | }) { |
| 954 | return Err(CliError::GitError { |
nothing calls this directly
no test coverage detected